/* ================================ */
/* Tiptap + DaisyUI Integration     */
/* ================================ */

/* ── Editor container ──────────────────────────────────── */

/* Snow-style wrapper: toolbar on top, editor below */
.tiptap-editor-wrapper {
  border: 1px solid var(--color-base-300);
  border-radius: 0.5rem;
  background-color: var(--color-base-100);
  overflow: hidden;
}

/* Bubble-style wrapper: just a bordered box */
.tiptap-bubble-wrapper {
  border: 1px solid var(--color-base-300);
  border-radius: 0.5rem;
  background-color: var(--color-base-100);
  overflow: hidden;
}

/* The ProseMirror editing surface */
.tiptap.ProseMirror {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  padding: 0.75rem;
  outline: none;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-base-content);
  background-color: var(--color-base-100);
  word-break: break-word;
}

/* ProseMirror block element spacing */
.tiptap.ProseMirror > * + * { margin-top: 0.5em; }
.tiptap.ProseMirror p { margin: 0; }
.tiptap.ProseMirror ul,
.tiptap.ProseMirror ol  { padding-left: 1.5rem; }
.tiptap.ProseMirror ul  { list-style-type: disc; }
.tiptap.ProseMirror ol  { list-style-type: decimal; }
.tiptap.ProseMirror blockquote {
  border-left: 3px solid var(--color-base-300);
  margin-left: 0;
  padding-left: 1rem;
  color: color-mix(in oklab, var(--color-base-content) 70%, transparent);
}
.tiptap.ProseMirror code {
  background: color-mix(in oklab, var(--color-base-content) 8%, transparent);
  border-radius: 0.25rem;
  padding: 0.1em 0.3em;
  font-size: 0.875em;
}
.tiptap.ProseMirror pre {
  background: color-mix(in oklab, var(--color-base-content) 8%, transparent);
  border-radius: 0.375rem;
  padding: 0.75rem;
  overflow-x: auto;
}

/* Comments: smaller */
.comment-form-container .tiptap.ProseMirror {
  min-height: 6rem;
  max-height: none;
}

/* Placeholder */
.tiptap.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: color-mix(in oklab, var(--color-base-content) 40%, transparent);
  font-style: italic;
  pointer-events: none;
  float: left;
  height: 0;
}

/* ── Fixed Snow-style toolbar ──────────────────────────── */

.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem;
  padding: 0.375rem 0.5rem;
  background-color: var(--color-base-200);
  border-bottom: 1px solid var(--color-base-300);
}

.tiptap-toolbar button {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-base-content);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background-color 0.15s;
  user-select: none;
}

.tiptap-toolbar button:hover {
  background-color: var(--color-base-300);
}

.tiptap-toolbar button.is-active {
  background-color: var(--color-primary);
  color: var(--color-primary-content);
}

.tiptap-toolbar button svg {
  width: 1.1rem;
  height: 1.1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.tiptap-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 1.25rem;
  background-color: var(--color-base-300);
  margin: 0 0.25rem;
}

/* Full toolbar wraps — allows two rows on narrow screens */
.tiptap-toolbar-full {
  flex-wrap: wrap;
}

/* Context-sensitive table controls bar (shown when cursor is in a table) */
.tiptap-table-controls {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem;
  padding: 0.25rem 0.5rem;
  background-color: color-mix(in oklab, var(--color-primary) 8%, var(--color-base-200));
  border-bottom: 1px solid var(--color-base-300);
  font-size: 0.75rem;
}

.tiptap-table-controls.is-visible { display: flex; }

.tiptap-table-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-base-content);
  font-size: 0.75rem;
  transition: background-color 0.15s;
}
.tiptap-table-controls button:hover {
  background-color: var(--color-base-300);
}
.tiptap-table-controls button svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ── Bubble (floating) menu ────────────────────────────── */

.tiptap-bubble-menu {
  display: flex;
  gap: 0.125rem;
  padding: 0.25rem;
  background-color: var(--color-base-200);
  border: 1px solid var(--color-base-300);
  border-radius: 0.5rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  z-index: 50;
}

.tiptap-bubble-menu button {
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-base-content);
  font-size: 0.75rem;
  font-weight: 600;
  transition: background-color 0.15s;
  user-select: none;
}

.tiptap-bubble-menu button:hover {
  background-color: var(--color-base-300);
}

.tiptap-bubble-menu button.is-active {
  background-color: var(--color-primary);
  color: var(--color-primary-content);
}

.tiptap-bubble-menu button svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ── Content display (detail views) ───────────────────── */

.tiptap-content {
  display: flow-root; /* contain floats */
}

.tiptap-content ul,
.tiptap-content ol  { padding-left: 1.5rem; }
.tiptap-content ul  { list-style-type: disc; }
.tiptap-content ol  { list-style-type: decimal; }

/* ── Image alignment ───────────────────────────────────── */

.tiptap.ProseMirror img,
.tiptap-content img {
  max-width: 100%;
  height: auto;
}

.tiptap.ProseMirror img.img-align-left,
.tiptap-content img.img-align-left {
  float: left;
  margin: 0 1rem 0.5rem 0;
}

.tiptap.ProseMirror img.img-align-center,
.tiptap-content img.img-align-center {
  display: block;
  margin: 0.5rem auto;
}

.tiptap.ProseMirror img.img-align-right,
.tiptap-content img.img-align-right {
  float: right;
  margin: 0 0 0.5rem 1rem;
}

/* ── Figure images (resizable / wrappable / captioned) ──── */

.tiptap.ProseMirror figure,
.tiptap-content figure {
  margin: 0.75rem 0;
  max-width: 100%;
}

.tiptap.ProseMirror figure img,
.tiptap-content figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0.25rem;
}

.tiptap.ProseMirror figure figcaption,
.tiptap-content figure figcaption {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
  color: color-mix(in oklab, var(--color-base-content) 65%, transparent);
}

/* Wrap (float) on the figure — width is set inline via style */
.tiptap.ProseMirror figure.img-align-left,
.tiptap-content figure.img-align-left {
  float: left;
  margin: 0.25rem 1rem 0.5rem 0;
}
.tiptap.ProseMirror figure.img-align-right,
.tiptap-content figure.img-align-right {
  float: right;
  margin: 0.25rem 0 0.5rem 1rem;
}

/* Editor-only: resize frame, drag handle, selection outline */
.tiptap.ProseMirror .tiptap-img-frame {
  position: relative;
  display: block;
  line-height: 0;
}
.tiptap.ProseMirror figure.ProseMirror-selectednode {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 0.25rem;
}
.tiptap.ProseMirror .tiptap-img-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  background: var(--color-primary);
  border: 2px solid var(--color-base-100);
  border-radius: 3px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.15s;
}
.tiptap.ProseMirror figure:hover .tiptap-img-handle,
.tiptap.ProseMirror figure.ProseMirror-selectednode .tiptap-img-handle {
  opacity: 1;
}

/* Image floating menu reuses bubble-menu styling; allow it to wrap */
.tiptap-image-menu {
  flex-wrap: wrap;
  max-width: 22rem;
}

/* Full / comment bubble menus: same styling as the bubble menu, but wrap */
.tiptap-bubble-full,
.tiptap-bubble-comment {
  flex-wrap: wrap;
  max-width: min(92vw, 34rem);
}

/* ── Bubble ⇄ toolbar chrome toggle (full / blog editors) ─ */
.tiptap-editor-wrapper.tiptap-chrome { position: relative; }

.tiptap-chrome-toggle {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  z-index: 5;
  width: 1.9rem;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-base-300);
  border-radius: 0.375rem;
  background-color: var(--color-base-200);
  color: var(--color-base-content);
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s, background-color 0.15s;
}
.tiptap-chrome-toggle:hover { opacity: 1; background-color: var(--color-base-300); }
.tiptap-chrome-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Keep the toolbar's right-edge buttons clear of the floating toggle
   (applies to both the full blog toolbar and the compact comment toolbar) */
.tiptap-editor-wrapper.tiptap-chrome .tiptap-toolbar { padding-right: 2.5rem; }

/* ── Tables ────────────────────────────────────────────── */

.tiptap.ProseMirror .tableWrapper,
.tiptap-content .tableWrapper {
  overflow-x: auto;
  margin: 1rem 0;
}

.tiptap.ProseMirror table,
.tiptap-content table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}

.tiptap.ProseMirror th,
.tiptap.ProseMirror td,
.tiptap-content th,
.tiptap-content td {
  border: 1px solid var(--color-base-300);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
  min-width: 4rem;
  position: relative;
}

.tiptap.ProseMirror th,
.tiptap-content th {
  background-color: var(--color-base-200);
  font-weight: 600;
}

.tiptap.ProseMirror tr:nth-child(even) td,
.tiptap-content tr:nth-child(even) td {
  background-color: color-mix(in oklab, var(--color-base-200) 40%, transparent);
}

/* Selected cell highlight (in editor) */
.tiptap.ProseMirror .selectedCell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--color-primary) 15%, transparent);
  pointer-events: none;
}

/* ── Highlight mark ────────────────────────────────────── */

.tiptap.ProseMirror mark,
.tiptap-content mark {
  background-color: color-mix(in oklab, oklch(0.9 0.15 90) 60%, transparent);
  border-radius: 0.15em;
  padding: 0 0.1em;
  color: inherit;
}

/* ── Backward-compat shim for Quill alignment classes ─── */
/* Keeps existing DB content rendering correctly until
   the migrate_quill_to_tiptap management command runs. */

.ql-align-center,
.tiptap-content .ql-align-center { text-align: center; }

.ql-align-right,
.tiptap-content .ql-align-right { text-align: right; }

.ql-align-justify,
.tiptap-content .ql-align-justify { text-align: justify; }
