/* ==========================================================================
   TipTap Editor - PDF-inspired Styling
   Flowayz Spec Editor with premium document feel
   ========================================================================== */

/* Container */
.tiptap-editor-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  /* overflow: visible to allow dropdown menus to extend outside */
}

/* Editor wrapper: auto overflow for scrollable content, clipped to border radius */
.tiptap-editor-container > .tiptap-editor-wrapper {
  border-radius: 0 0 12px 12px;
  overflow: auto;
}

/* Toolbar */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 12px 16px;
  background: var(--bg-surface-hover);
  border-bottom: 1px solid var(--border-default);
}

.tiptap-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  border-right: 1px solid var(--border-default);
}

.tiptap-toolbar-group:last-child {
  border-right: none;
}

.tiptap-toolbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tiptap-toolbar button:hover {
  background: var(--bg-accent-10, rgba(56, 178, 172, 0.1));
  color: var(--text-primary);
}

.tiptap-toolbar button.is-active {
  background: var(--accent, #38B2AC);
  color: var(--accent-contrast, #fff);
}

.tiptap-toolbar button svg {
  width: 18px;
  height: 18px;
}

.tiptap-toolbar .heading-btn {
  font-weight: 700;
  font-size: 14px;
  width: auto;
  padding: 6px 10px;
}

/* Editor Content Area */
.spec-editor-content {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  padding: 2rem 2.5rem;
  min-height: 500px;
  max-width: 850px;
  margin: 0 auto;
  background: var(--bg-surface);
}

.spec-editor-content:focus {
  outline: none;
}

/* Dark mode: Override prose styles for better visibility */
html.dark .spec-editor-content,
html[data-theme="dark"] .spec-editor-content,
[data-mode="dark"] .spec-editor-content {
  color: var(--text-primary) !important;
}

html.dark .spec-editor-content p,
html[data-theme="dark"] .spec-editor-content p,
[data-mode="dark"] .spec-editor-content p {
  color: var(--text-primary) !important;
}

/* Focus state for editor container */
.tiptap-editor-wrapper.is-focused {
  box-shadow: 0 0 0 3px var(--accent-20, rgba(56, 178, 172, 0.15));
}

/* ==========================================================================
   Typography - PDF-inspired headings
   ========================================================================== */

/* Sprint 6.3 — Spec viewer Notion-style (Steve Jobs Neat)
   Migration Poppins → Inter (--font-primary) pour cohérence avec le
   reste de l'app post-Sprint 1.1. Suppression des bordures sous-H1/H2
   colorées (coral, teal) qui datent du PDF-inspired pré-design system :
   on garde une hiérarchie purement typographique (taille + weight),
   façon Notion / Linear Docs / Things-style document. Le coup d'éditorial
   reste réservé au PDF généré (qui conserve ses couleurs brand). */

.spec-editor-content h1 {
  font-family: var(--font-primary);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.spec-editor-content h1:first-child {
  margin-top: 0;
}

.spec-editor-content h2 {
  font-family: var(--font-primary);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.spec-editor-content h3 {
  font-family: var(--font-primary);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

/* Dark mode heading colors — heritent maintenant de var(--text-primary)
   qui s'adapte automatiquement au thème via tokens sémantiques.
   Les anciens overrides forçaient des bleus/teal qui cassaient
   la hiérarchie typographique pure (Sprint 6.3). */

/* ==========================================================================
   Paragraphs & Text
   ========================================================================== */

.spec-editor-content p {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.spec-editor-content strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* Dark mode: Make bold text more visible */
html.dark .spec-editor-content strong,
html[data-theme="dark"] .spec-editor-content strong,
[data-mode="dark"] .spec-editor-content strong {
  color: #F8FAFC; /* Bright white for better contrast */
  font-weight: 700;
}

.spec-editor-content em {
  font-style: italic;
  color: var(--text-primary);
}

/* Dark mode: Make italic text visible */
html.dark .spec-editor-content em,
html[data-theme="dark"] .spec-editor-content em,
[data-mode="dark"] .spec-editor-content em {
  color: #E2E8F0; /* Slightly muted but visible */
}

.spec-editor-content u {
  text-decoration: underline;
  text-decoration-color: var(--flowayz-teal, #38B2AC);
  text-underline-offset: 2px;
}

/* ==========================================================================
   Lists
   ========================================================================== */

.spec-editor-content ul,
.spec-editor-content ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.spec-editor-content ul {
  list-style-type: disc;
}

.spec-editor-content ol {
  list-style-type: decimal;
}

.spec-editor-content li {
  margin-bottom: 0.5rem;
  padding-left: 0.25rem;
}

.spec-editor-content li > p {
  margin-bottom: 0.25rem;
}

/* Defense in depth: masque les <li>/<p> vides si du contenu sale échappe
   au cleanup server-side (legacy non-backfillé, import externe, etc.).
   Cause historique : LLM générant des blank-lines entre items → empty
   <li> intercalés. Nettoyé à la source par SpecMarkdownRenderer ; ce CSS
   n'est qu'un filet de sécurité. Support universel (IE9+ evergreen). */
.spec-editor-content li:empty,
.spec-editor-content li > p:empty:only-child {
  display: none;
}

.spec-editor-content ul ul,
.spec-editor-content ol ol,
.spec-editor-content ul ol,
.spec-editor-content ol ul {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Custom bullet styling */
.spec-editor-content ul li::marker {
  color: var(--flowayz-teal, #38B2AC);
}

.spec-editor-content ol li::marker {
  color: var(--flowayz-navy, #1A3C6B);
  font-weight: 600;
}

html.dark .spec-editor-content ol li::marker,
html[data-theme="dark"] .spec-editor-content ol li::marker {
  color: #93C5FD;
}

/* ==========================================================================
   Blockquotes - Highlight style
   ========================================================================== */

.spec-editor-content blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--flowayz-cream, #FFF5E4);
  border-left: 4px solid var(--flowayz-gold, #FFD166);
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--text-secondary);
}

.spec-editor-content blockquote p {
  margin-bottom: 0;
}

html.dark .spec-editor-content blockquote,
html[data-theme="dark"] .spec-editor-content blockquote {
  background: var(--accent-10, rgba(255, 209, 102, 0.1));
  border-left-color: var(--flowayz-gold, #FFD166);
}

/* ==========================================================================
   Code blocks
   ========================================================================== */

.spec-editor-content code {
  font-family: 'Fira Code', 'JetBrains Mono', 'Courier New', monospace;
  font-size: 14px;
  background: var(--bg-surface-hover, #EDF2F7);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-red, #E53E3E);
}

html.dark .spec-editor-content code,
html[data-theme="dark"] .spec-editor-content code {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-red, #FC8181);
}

.spec-editor-content pre {
  margin: 1.5rem 0;
  padding: 1.25rem;
  background: var(--bg-code-block, #1A202C);
  border-radius: 8px;
  overflow-x: auto;
}

.spec-editor-content pre code {
  background: transparent;
  padding: 0;
  color: var(--text-code, #E2E8F0);
  font-size: 14px;
  line-height: 1.6;
}

/* ==========================================================================
   Horizontal Rule
   ========================================================================== */

.spec-editor-content hr {
  margin: 2rem 0;
  border: none;
  height: 2px;
  background: linear-gradient(to right, var(--flowayz-teal, #38B2AC), var(--flowayz-coral, #FF7B54), var(--flowayz-gold, #FFD166));
  border-radius: 1px;
}

/* ==========================================================================
   Links
   ========================================================================== */

.spec-editor-content a {
  color: var(--flowayz-teal, #38B2AC);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.spec-editor-content a:hover {
  border-bottom-color: var(--flowayz-teal, #38B2AC);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.spec-editor-content table {
  width: 100%;
  margin: 1.5rem 0;
  border-collapse: collapse;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.spec-editor-content th {
  background: var(--flowayz-navy, #1A3C6B);
  color: white;
  font-weight: 600;
  padding: 12px 16px;
  text-align: left;
  font-size: 15px;
}

.spec-editor-content td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  font-size: 15px;
}

.spec-editor-content tr:last-child td {
  border-bottom: none;
}

.spec-editor-content tr:nth-child(even) td {
  background: var(--bg-surface-hover);
}

html.dark .spec-editor-content th,
html[data-theme="dark"] .spec-editor-content th,
[data-mode="dark"] .spec-editor-content th {
  background: #1E3A5F;
  color: var(--text-inverse, #fff);
}

html.dark .spec-editor-content tr:nth-child(even) td,
[data-mode="dark"] .spec-editor-content tr:nth-child(even) td {
  background: rgba(51, 65, 85, 0.4);
}

/* ==========================================================================
   Placeholder
   ========================================================================== */

.spec-editor-content p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-tertiary);
  pointer-events: none;
  height: 0;
  font-style: italic;
}

/* ==========================================================================
   Section highlights (optional - for key sections)
   ========================================================================== */

.spec-editor-content .highlight-section {
  background: var(--flowayz-cream, #FFF5E4);
  padding: 1.5rem;
  border-radius: 8px;
  border-left: 4px solid var(--flowayz-gold, #FFD166);
  margin: 1.5rem 0;
}

html.dark .spec-editor-content .highlight-section,
html[data-theme="dark"] .spec-editor-content .highlight-section {
  background: rgba(var(--flowayz-gold-rgb, 255, 209, 102), 0.08);
}

/* ==========================================================================
   Save Status
   ========================================================================== */

.tiptap-save-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==========================================================================
   Read-only mode styling
   ========================================================================== */

.spec-editor-content[contenteditable="false"] {
  cursor: default;
}

.spec-editor-content[contenteditable="false"]:focus {
  outline: none;
  box-shadow: none;
}

/* ==========================================================================
   Print styles (for consistency with PDF)
   ========================================================================== */

@media print {
  .tiptap-toolbar {
    display: none;
  }

  .spec-editor-content {
    padding: 0;
    max-width: none;
  }

  .spec-editor-content h1 {
    page-break-after: avoid;
  }

  .spec-editor-content h2,
  .spec-editor-content h3 {
    page-break-after: avoid;
  }

  .spec-editor-content pre,
  .spec-editor-content blockquote {
    page-break-inside: avoid;
  }
}

/* ==========================================================================
   Responsive adjustments
   ========================================================================== */

@media (max-width: 768px) {
  .spec-editor-content {
    padding: 1.5rem;
    font-size: 15px;
  }

  .spec-editor-content h1 {
    font-size: 26px;
  }

  .spec-editor-content h2 {
    font-size: 22px;
  }

  .spec-editor-content h3 {
    font-size: 16px;
  }

  .tiptap-toolbar {
    padding: 8px 12px;
    gap: 1px;
  }

  .tiptap-toolbar button {
    width: 28px;
    height: 28px;
  }

  .tiptap-toolbar-group {
    padding: 0 4px;
  }
}

/* ==========================================================================
   Toolbar Dropdowns
   ========================================================================== */

.toolbar-dropdown {
  position: relative;
  display: inline-flex;
}

.toolbar-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  min-width: 180px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-dropdown, var(--bg-surface));
  border: 1px solid var(--border-default);
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  padding: 0.25rem;
  margin-top: 4px;
}


/* Ouvre au clic via JS (classe .is-open) — pas de hover pour support tactile */
.toolbar-dropdown.is-open .toolbar-dropdown-menu {
  display: block;
}

.toolbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 0.8125rem;
  border-radius: 0.375rem;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.toolbar-dropdown-item:hover {
  background: var(--bg-surface-hover);
}

.toolbar-dropdown-item.is-active {
  background: var(--accent-10);
  color: var(--accent);
}

/* Chevron rotation when open */
.toolbar-dropdown.is-open .toolbar-dropdown-trigger .chevron-icon {
  transform: rotate(180deg);
}
.toolbar-dropdown-trigger .chevron-icon {
  transition: transform 0.15s ease;
}

.toolbar-dropdown-item svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .toolbar-dropdown-menu {
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    top: auto;
    bottom: 60px;
    min-width: auto;
    max-height: 50vh;
  }
}

/* ==========================================================================
   Slash Command Menu
   ========================================================================== */

.slash-command-menu {
  display: none;
  z-index: 9999;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
  padding: 0.25rem;
}

.slash-command-category {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

.slash-command-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 0.8125rem;
  border-radius: 0.375rem;
  cursor: pointer;
  text-align: left;
}

.slash-command-item:hover,
.slash-command-item.selected {
  background: var(--accent-10, rgba(56, 178, 172, 0.1));
}

.slash-command-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

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

.slash-command-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.8125rem;
}

/* ==========================================================================
   Callout Blocks
   ========================================================================== */

.callout-block {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  border-left: 4px solid;
}

.callout-block[data-callout-type="info"] {
  background: var(--color-blue-bg);
  border-color: var(--color-blue);
}

.callout-block[data-callout-type="warning"] {
  background: var(--color-amber-bg);
  border-color: var(--color-amber);
}

.callout-block[data-callout-type="success"] {
  background: var(--color-green-bg);
  border-color: var(--color-green);
}

.callout-block[data-callout-type="error"] {
  background: var(--color-red-bg);
  border-color: var(--color-red);
}

.callout-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 0.125rem;
  user-select: none;
}

.callout-content {
  flex: 1;
  min-width: 0;
}

.callout-content p {
  margin-bottom: 0.25rem;
}

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

/* ==========================================================================
   Task Lists / Checkboxes
   ========================================================================== */

.spec-editor-content ul[data-type="taskList"],
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"],
.collaborative-editor-content ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
}

.spec-editor-content ul[data-type="taskList"] li,
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li,
.collaborative-editor-content ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding-left: 0;
}

.spec-editor-content ul[data-type="taskList"] li label,
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li label,
.collaborative-editor-content ul[data-type="taskList"] li label {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.spec-editor-content ul[data-type="taskList"] li label input[type="checkbox"],
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li label input[type="checkbox"],
.collaborative-editor-content ul[data-type="taskList"] li label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
  border-radius: 3px;
}

.spec-editor-content ul[data-type="taskList"] li div,
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li div,
.collaborative-editor-content ul[data-type="taskList"] li div {
  flex: 1;
  min-width: 0;
}

/* Checked task items: strikethrough */
.spec-editor-content ul[data-type="taskList"] li[data-checked="true"] > div p,
.tiptap-editor-wrapper .ProseMirror ul[data-type="taskList"] li[data-checked="true"] > div p,
.collaborative-editor-content ul[data-type="taskList"] li[data-checked="true"] > div p {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

/* ==========================================================================
   TipTap Tables (interactive editing)
   ========================================================================== */

.spec-editor-content .tableWrapper,
.tiptap-editor-wrapper .ProseMirror .tableWrapper,
.collaborative-editor-content .tableWrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
}

.tiptap-editor-wrapper .ProseMirror table,
.collaborative-editor-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  table-layout: fixed;
}

.tiptap-editor-wrapper .ProseMirror th,
.tiptap-editor-wrapper .ProseMirror td,
.collaborative-editor-content th,
.collaborative-editor-content td {
  border: 1px solid var(--border-default);
  padding: 0.5rem 0.75rem;
  min-width: 80px;
  vertical-align: top;
  position: relative;
}

.tiptap-editor-wrapper .ProseMirror th,
.collaborative-editor-content th {
  background: var(--bg-surface-hover);
  font-weight: 600;
  text-align: left;
}

/* Dark mode: headers, bordures, zebra */
[data-mode="dark"] .tiptap-editor-wrapper .ProseMirror th,
[data-mode="dark"] .collaborative-editor-content th {
  background: #1E3A5F;
  color: #F1F5F9;
}

[data-mode="dark"] .tiptap-editor-wrapper .ProseMirror th,
[data-mode="dark"] .tiptap-editor-wrapper .ProseMirror td,
[data-mode="dark"] .collaborative-editor-content th,
[data-mode="dark"] .collaborative-editor-content td {
  border-color: #475569;
}

/* Selected cells */
.tiptap-editor-wrapper .ProseMirror .selectedCell,
.collaborative-editor-content .selectedCell {
  background: var(--accent-10, rgba(56, 178, 172, 0.1));
}

[data-mode="dark"] .tiptap-editor-wrapper .ProseMirror .selectedCell,
[data-mode="dark"] .collaborative-editor-content .selectedCell {
  background: rgba(56, 178, 172, 0.25);
}

/* Column resize handle */
.tiptap-editor-wrapper .ProseMirror .column-resize-handle,
.collaborative-editor-content .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
  cursor: col-resize;
  z-index: 10;
}

/* ==========================================================================
   AI Generation Panel
   ========================================================================== */

.ai-panel {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface);
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease, padding 0.2s ease;
}

.ai-panel.hidden {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border: none;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.ai-panel-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.ai-panel-close {
  margin-left: auto;
  padding: 0.25rem;
  color: var(--text-tertiary);
  cursor: pointer;
  border: none;
  background: none;
  border-radius: 0.25rem;
}
.ai-panel-close:hover { color: var(--text-primary); }

.ai-panel-textarea {
  width: 100%;
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: 0.5rem;
  padding: 0.75rem;
  font-size: 0.875rem;
  resize: none;
  outline: none;
  font-family: inherit;
}
.ai-panel-textarea:focus {
  border-color: var(--accent);
}

.ai-panel-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.ai-pill-group {
  display: flex;
  gap: 0.25rem;
}

.ai-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all 0.15s;
  background: transparent;
  color: var(--text-secondary);
}
.ai-pill:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}
.ai-pill.active {
  background: var(--accent-10);
  color: var(--accent);
  border-color: var(--accent);
}

.ai-pill-cost {
  color: var(--text-tertiary);
}

.ai-generate-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  transition: opacity 0.15s;
}
.ai-generate-btn:hover { opacity: 0.9; }

.ai-sep {
  width: 1px;
  height: 1.25rem;
  background: var(--border-default);
}

@media (max-width: 768px) {
  .ai-panel { padding: 0.75rem 1rem; }
}

/* ==========================================================================
   Table Context Menu
   ========================================================================== */

.table-context-menu {
  position: fixed;
  z-index: 60;
  background: var(--bg-dropdown, var(--bg-surface));
  border: 1px solid var(--border-default);
  border-radius: 0.625rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2), 0 12px 40px rgba(0,0,0,0.15);
  padding: 0.375rem;
  min-width: 220px;
  max-height: 80vh;
  overflow-y: auto;
}

.table-context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1.4;
  transition: background 0.1s;
}
.table-context-menu-item:hover {
  background: var(--bg-surface-hover);
}
.table-context-menu-item--danger {
  color: #ef4444;
}
.table-context-menu-item--danger:hover {
  background: rgba(239,68,68,0.08);
}

.table-context-menu-separator {
  height: 1px;
  background: var(--border-default);
  margin: 0.25rem 0.375rem;
}

/* ==========================================================================
   Table of Contents Panel
   ========================================================================== */

.toc-panel {
  position: fixed;
  right: 1rem;
  top: 120px;
  width: 240px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 20;
}

.toc-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-default);
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.375rem 0.75rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item:hover {
  color: var(--accent);
  background: var(--bg-surface-hover);
}

.toc-level-1 { font-weight: 600; color: var(--text-primary); }
.toc-level-2 { font-weight: 500; }
.toc-level-3 { font-size: 0.75rem; }

@media (max-width: 1024px) {
  .toc-panel {
    position: fixed;
    right: 0;
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 40vh;
    border-radius: 1rem 1rem 0 0;
    z-index: 40;
  }
}

/* ==========================================================================
   Document Editor Page Layout
   ========================================================================== */

.document-editor-page {
  min-height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.doc-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-surface);
  padding: 0 1rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.doc-title-input {
  background: transparent;
  border: none;
  outline: none;
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--shared-heading-font, var(--font-heading, 'Poppins', sans-serif));
  color: var(--text-primary);
  width: 100%;
  padding: 0;
  line-height: 1.2;
}
.doc-title-input::placeholder { color: var(--text-tertiary); }

.doc-canvas {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 3rem 5rem;
}

@media (max-width: 768px) {
  .doc-canvas { padding: 1.5rem 1.25rem 4rem; }
  .doc-title-input { font-size: 1.5rem; }
}

.doc-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  padding: 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 52px;
  background: var(--bg-surface);
  z-index: 30;
  /* Refonte 2026-05-03 : avec ~18 boutons, scroll horizontal sur écrans étroits
     plutôt que wrap (préserve la sticky bar à hauteur constante). */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}
.doc-toolbar::-webkit-scrollbar { height: 4px; }
.doc-toolbar::-webkit-scrollbar-track { background: transparent; }
.doc-toolbar::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 2px; }

@media (max-width: 768px) {
  .doc-toolbar { gap: 3px; padding-left: 0.75rem; padding-right: 0.75rem; }
  .doc-toolbar .toolbar-btn { padding: 0.375rem 0.4rem; min-width: 1.75rem; }
}

/* Toolbar buttons (document editor specific) */
.doc-toolbar .toolbar-btn {
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
  color: var(--text-secondary);
  transition: background-color 0.15s, color 0.15s;
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.doc-toolbar .toolbar-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.doc-toolbar .toolbar-btn.active {
  background: var(--accent-10);
  color: var(--accent);
}

.toolbar-sep {
  width: 1px;
  height: 1.25rem;
  background: var(--border-default);
  margin: 0 0.25rem;
  flex-shrink: 0;
}

/* Save status badge */
.save-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-surface-hover);
  color: var(--text-tertiary);
  white-space: nowrap;
}
.save-badge.saved { color: #22c55e; background: rgba(34,197,94,0.1); animation: save-flash 0.4s ease; }
.save-badge.saving { color: var(--text-tertiary); }
.save-badge.error { color: #ef4444; background: rgba(239,68,68,0.1); }

@keyframes save-flash {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   Document Heading Styles (themed by data-heading-style)
   ========================================================================== */

.tiptap-editor-wrapper .ProseMirror h1,
.tiptap-editor-wrapper .ProseMirror h2,
.tiptap-editor-wrapper .ProseMirror h3 {
  font-family: var(--shared-heading-font, var(--font-heading, 'Poppins', sans-serif));
}

/* underline (default) */
[data-heading-style="underline"] .tiptap-editor-wrapper .ProseMirror h1 {
  border-bottom: 3px solid var(--shared-accent, var(--accent));
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}
[data-heading-style="underline"] .tiptap-editor-wrapper .ProseMirror h2 {
  border-bottom: 2px solid var(--shared-accent, var(--accent));
  padding-bottom: 0.375rem;
  margin-bottom: 0.75rem;
}

/* accent-text */
[data-heading-style="accent-text"] .tiptap-editor-wrapper .ProseMirror h1,
[data-heading-style="accent-text"] .tiptap-editor-wrapper .ProseMirror h2 {
  color: var(--shared-accent, var(--accent));
}

/* left-border */
[data-heading-style="left-border"] .tiptap-editor-wrapper .ProseMirror h1 {
  border-left: 5px solid var(--shared-accent, var(--accent));
  padding-left: 1rem;
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 6%, transparent);
  border-radius: 0 0.375rem 0.375rem 0;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}
[data-heading-style="left-border"] .tiptap-editor-wrapper .ProseMirror h2 {
  border-left: 4px solid var(--shared-accent, var(--accent));
  padding-left: 0.875rem;
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 5%, transparent);
  border-radius: 0 0.375rem 0.375rem 0;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

/* background */
[data-heading-style="background"] .tiptap-editor-wrapper .ProseMirror h1 {
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 10%, transparent);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
}
[data-heading-style="background"] .tiptap-editor-wrapper .ProseMirror h2 {
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 8%, transparent);
  padding: 0.375rem 0.875rem;
  border-radius: 0.375rem;
}

/* overline */
[data-heading-style="overline"] .tiptap-editor-wrapper .ProseMirror h1 {
  border-top: 3px solid var(--shared-accent, var(--accent));
  padding-top: 0.5rem;
  margin-top: 2rem;
}
[data-heading-style="overline"] .tiptap-editor-wrapper .ProseMirror h2 {
  border-top: 2px solid var(--shared-accent, var(--accent));
  padding-top: 0.375rem;
  margin-top: 1.5rem;
}

/* none — reset all */
[data-heading-style="none"] .tiptap-editor-wrapper .ProseMirror h1,
[data-heading-style="none"] .tiptap-editor-wrapper .ProseMirror h2 {
  border-bottom: none;
  border-top: none;
  border-left: none;
  background: transparent;
  padding-bottom: 0;
  padding-top: 0;
  padding-left: 0;
}

/* h3 accent for all templates */
.tiptap-editor-wrapper .ProseMirror h3 {
  color: var(--shared-accent, var(--accent));
}

/* ==========================================================================
   Document Blockquote Styles (themed by data-heading-style)
   ========================================================================== */

.tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: 4px solid var(--shared-accent, var(--accent));
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 6%, transparent);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 0 0.5rem 0.5rem 0;
}

[data-heading-style="none"] .tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: 3px solid var(--border-default, #e5e7eb);
  background: transparent;
  box-shadow: none;
  padding: 0.5rem 1rem;
  border-radius: 0;
}

[data-heading-style="accent-text"] .tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: 4px solid var(--shared-accent, var(--accent));
  background: transparent;
  color: var(--shared-accent, var(--accent));
  font-style: italic;
}

[data-heading-style="left-border"] .tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: 5px solid var(--shared-accent, var(--accent));
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 6%, transparent);
  border-radius: 0 0.5rem 0.5rem 0;
}

[data-heading-style="background"] .tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: none;
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 10%, transparent);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
}

[data-heading-style="overline"] .tiptap-editor-wrapper .ProseMirror blockquote {
  border-left: none;
  border-top: 3px solid var(--shared-accent, var(--accent));
  background: color-mix(in srgb, var(--shared-accent, var(--accent)) 5%, transparent);
  border-radius: 0;
  padding: 0.75rem 1rem;
}

/* ==========================================================================
   Zen Mode
   ========================================================================== */

.document-editor-page.zen-mode .doc-topbar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.document-editor-page.zen-mode:hover .doc-topbar {
  opacity: 1;
  pointer-events: auto;
}

.document-editor-page.zen-mode .doc-toolbar {
  opacity: 0.3;
  transition: opacity 0.3s;
}

.document-editor-page.zen-mode .doc-toolbar:hover {
  opacity: 1;
}

.document-editor-page.zen-mode .doc-canvas {
  max-width: 100%;
  padding-left: 10%;
  padding-right: 10%;
}

.document-editor-page.zen-mode .toc-panel {
  display: none;
}

/* ==========================================================================
   Flowayz Ref styles (inline chips + cards)
   ========================================================================== */

.spec-editor-content a[data-flowayz-ref],
.tiptap-editor-wrapper .ProseMirror a[data-flowayz-ref],
.collaborative-editor-content a[data-flowayz-ref] {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  background: var(--accent-10, rgba(56, 178, 172, 0.1));
  border-radius: 0.25rem;
  color: var(--accent);
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  border-bottom: none;
}

.spec-editor-content a[data-flowayz-ref]:hover,
.tiptap-editor-wrapper .ProseMirror a[data-flowayz-ref]:hover,
.collaborative-editor-content a[data-flowayz-ref]:hover {
  background: var(--accent-20, rgba(56, 178, 172, 0.2));
  border-bottom: none;
}

.spec-editor-content div[data-flowayz-card],
.tiptap-editor-wrapper .ProseMirror div[data-flowayz-card],
.collaborative-editor-content div[data-flowayz-card] {
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.spec-editor-content div[data-flowayz-card]:hover,
.tiptap-editor-wrapper .ProseMirror div[data-flowayz-card]:hover,
.collaborative-editor-content div[data-flowayz-card]:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ==========================================================================
   Drag Handle
   ========================================================================== */

.tiptap-drag-handle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  color: var(--text-tertiary);
  cursor: grab;
  transition: color 0.15s, background-color 0.15s;
  user-select: none;
}

.tiptap-drag-handle:hover {
  color: var(--text-secondary);
  background: var(--bg-surface-hover);
}

.tiptap-drag-handle:active {
  cursor: grabbing;
  color: var(--accent);
}

/* Hide drag handle on mobile */
@media (max-width: 768px) {
  .tiptap-drag-handle {
    display: none !important;
  }
}
