/**
 * Theme-Adaptive TipTap Editor Stylesheet (Light & Dark Mode)
 * BHC Academy - new_web
 */

/* Container & Shell */
.tiptap-wrapper {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tiptap-wrapper:focus-within {
  border-color: var(--primary, #2563eb);
  box-shadow: 0 0 0 3px var(--primary-surface, rgba(37, 99, 235, 0.15));
}

/* Toolbar */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg-main, #f8fafc);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  user-select: none;
}

.tiptap-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  border-right: 1px solid var(--border-color, #e2e8f0);
}

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

.tiptap-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted, #475569);
  font-size: 0.82rem;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  transition: all 0.15s ease;
  line-height: 1;
}

.tiptap-btn:hover {
  background: var(--primary-surface, #eff6ff);
  color: var(--primary, #2563eb);
}

.tiptap-btn.is-active {
  background: var(--primary, #2563eb);
  color: #ffffff;
  border-color: var(--primary, #2563eb);
  font-weight: 700;
}

[data-theme="dark"] .tiptap-btn.is-active {
  background: var(--primary, #38bdf8);
  color: #0b0f19;
  border-color: var(--primary, #38bdf8);
}

.tiptap-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Editor Canvas / ProseMirror */
.tiptap-canvas {
  padding: 14px 16px;
  cursor: text;
  flex: 1;
  background: var(--bg-surface, #ffffff);
}

.tiptap-canvas .ProseMirror {
  outline: none;
  color: var(--text-main, #0f172a);
  font-size: 0.95rem;
  line-height: 1.7;
  min-height: var(--tiptap-min-height, 180px);
}

/* Typography Inside Editor & Rendered Output */
.tiptap-canvas .ProseMirror > *:first-child,
.tiptap-rendered-content > *:first-child {
  margin-top: 0 !important;
}

.tiptap-canvas .ProseMirror > *:last-child,
.tiptap-rendered-content > *:last-child {
  margin-bottom: 0 !important;
}

.tiptap-canvas .ProseMirror p,
.tiptap-rendered-content p {
  margin: 0.5rem 0 0.8rem 0;
  color: var(--text-main, #0f172a);
}

.tiptap-canvas .ProseMirror h1,
.tiptap-rendered-content h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main, #0f172a);
  margin: 1.25rem 0 0.5rem 0;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  padding-bottom: 0.35rem;
}

.tiptap-canvas .ProseMirror h2,
.tiptap-rendered-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main, #0f172a);
  margin: 1.1rem 0 0.4rem 0;
}

.tiptap-canvas .ProseMirror h3,
.tiptap-rendered-content h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary, #2563eb);
  margin: 0.9rem 0 0.3rem 0;
}

.tiptap-canvas .ProseMirror ul,
.tiptap-rendered-content ul {
  list-style-type: disc;
  padding-left: 1.4rem;
  margin: 0.5rem 0 0.8rem 0;
}

.tiptap-canvas .ProseMirror ol,
.tiptap-rendered-content ol {
  list-style-type: decimal;
  padding-left: 1.4rem;
  margin: 0.5rem 0 0.8rem 0;
}

.tiptap-canvas .ProseMirror li,
.tiptap-rendered-content li {
  margin-bottom: 0.25rem;
  color: var(--text-main, #0f172a);
}

.tiptap-canvas .ProseMirror code,
.tiptap-rendered-content code {
  background: var(--primary-surface, #eff6ff);
  color: var(--primary, #2563eb);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.85em;
  border: 1px solid var(--primary-border, #bfdbfe);
}

.tiptap-canvas .ProseMirror pre,
.tiptap-rendered-content pre {
  background: var(--bg-main, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-left: 3px solid var(--primary, #2563eb);
  border-radius: 6px;
  padding: 0.9rem 1.1rem;
  margin: 0.8rem 0;
  overflow-x: auto;
}

.tiptap-canvas .ProseMirror pre code,
.tiptap-rendered-content pre code {
  background: transparent;
  color: var(--text-main, #0f172a);
  border: none;
  padding: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  display: block;
}

[data-theme="dark"] .tiptap-canvas .ProseMirror pre,
[data-theme="dark"] .tiptap-rendered-content pre {
  background: #080d16;
  border-color: rgba(56, 189, 248, 0.25);
  border-left-color: var(--primary, #38bdf8);
}

[data-theme="dark"] .tiptap-canvas .ProseMirror pre code,
[data-theme="dark"] .tiptap-rendered-content pre code {
  color: #79c0ff;
}

.tiptap-canvas .ProseMirror blockquote,
.tiptap-rendered-content blockquote {
  border-left: 3px solid var(--primary, #2563eb);
  background: var(--primary-surface, #eff6ff);
  padding: 0.6rem 1rem;
  margin: 0.8rem 0;
  border-radius: 0 4px 4px 0;
  color: var(--text-muted, #475569);
  font-style: italic;
}

.tiptap-canvas .ProseMirror hr,
.tiptap-rendered-content hr {
  border: none;
  border-top: 1px solid var(--border-color, #e2e8f0);
  margin: 1.25rem 0;
}

.tiptap-canvas .ProseMirror a,
.tiptap-rendered-content a {
  color: var(--primary, #2563eb);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

.tiptap-canvas .ProseMirror a:hover,
.tiptap-rendered-content a:hover {
  color: var(--primary-hover, #1d4ed8);
}

/* Placeholder */
.tiptap-canvas .ProseMirror p.is-editor-empty:first-child::before {
  color: var(--text-dim, #94a3b8);
  content: attr(data-placeholder);
  float: left;
  height: 0;
  pointer-events: none;
}

/* Rendered Content Typography Utility */
.tiptap-rendered-content {
  color: var(--text-main, #0f172a);
  font-size: 0.95rem;
  line-height: 1.75;
}

/* ==========================================================================
   IMAGE ELEMENTS
   ========================================================================== */
.tiptap-canvas .ProseMirror img,
.tiptap-rendered-content img,
.tiptap-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm, 6px);
  margin: 1.15rem auto;
  display: block;
  border: 1px solid var(--border-color, #e2e8f0);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tiptap-canvas .ProseMirror img.ProseMirror-selectednode {
  outline: 3px solid var(--primary, #2563eb);
  box-shadow: 0 0 0 4px var(--primary-surface, rgba(37, 99, 235, 0.2));
}

[data-theme="dark"] .tiptap-canvas .ProseMirror img,
[data-theme="dark"] .tiptap-rendered-content img {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   VIDEO & YOUTUBE EMBED ELEMENTS
   ========================================================================== */
.tiptap-canvas .ProseMirror iframe,
.tiptap-rendered-content iframe,
.tiptap-youtube-embed,
.tiptap-canvas .ProseMirror video,
.tiptap-rendered-content video {
  width: 100%;
  max-width: 720px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm, 8px);
  margin: 1.25rem auto;
  display: block;
  border: 1px solid var(--border-color, #e2e8f0);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  background: #000;
}

[data-theme="dark"] .tiptap-canvas .ProseMirror iframe,
[data-theme="dark"] .tiptap-rendered-content iframe,
[data-theme="dark"] .tiptap-youtube-embed {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   TABLE ELEMENTS & CONTEXTUAL TOOLBAR
   ========================================================================== */
.tiptap-table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: var(--primary-surface, rgba(37, 99, 235, 0.06));
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  font-size: 0.78rem;
  transition: all 0.2s ease;
}

[data-theme="dark"] .tiptap-table-toolbar {
  background: rgba(56, 189, 248, 0.08);
}

.tiptap-table-label {
  font-weight: 700;
  color: var(--primary, #2563eb);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tiptap-divider {
  width: 1px;
  height: 18px;
  background: var(--border-color, #e2e8f0);
  margin: 0 3px;
}

.tiptap-canvas .ProseMirror table,
.tiptap-rendered-content table,
.tiptap-table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  margin: 1.25rem 0;
  overflow: hidden;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--border-color, #e2e8f0);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.05));
}

.tiptap-canvas .ProseMirror th,
.tiptap-rendered-content th {
  background: var(--bg-main, #f8fafc);
  color: var(--text-main, #0f172a);
  font-weight: 700;
  text-align: left;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color, #e2e8f0);
  font-size: 0.88rem;
  position: relative;
}

.tiptap-canvas .ProseMirror td,
.tiptap-rendered-content td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color, #e2e8f0);
  vertical-align: top;
  box-sizing: border-box;
  font-size: 0.88rem;
  color: var(--text-main, #0f172a);
  position: relative;
}

.tiptap-canvas .ProseMirror .selectedCell:after {
  z-index: 2;
  position: absolute;
  content: "";
  left: 0; right: 0; top: 0; bottom: 0;
  background: rgba(37, 99, 235, 0.15);
  pointer-events: none;
}

.tiptap-canvas .ProseMirror .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: -2px;
  width: 4px;
  background-color: var(--primary, #2563eb);
  pointer-events: none;
}

[data-theme="dark"] .tiptap-canvas .ProseMirror th,
[data-theme="dark"] .tiptap-rendered-content th {
  background: rgba(255, 255, 255, 0.06);
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .tiptap-canvas .ProseMirror td,
[data-theme="dark"] .tiptap-rendered-content td {
  border-color: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

[data-theme="dark"] .tiptap-canvas .ProseMirror table,
[data-theme="dark"] .tiptap-rendered-content table {
  border-color: rgba(255, 255, 255, 0.12);
}

