/*
 * TipTap Editor Styles
 * Coherent with shadcn/ui theme
 */

/* Editor container */
.tiptap-editor {
  --tiptap-color-text: var(--foreground);
  --tiptap-color-text-muted: var(--muted-foreground);
  --tiptap-color-bg: var(--card);
  --tiptap-color-border: var(--border);
  --tiptap-color-primary: var(--primary);
}

/* Editor content area */
.tiptap-content {
  min-height: 50vh;
  padding: 1rem 0;
  outline: none;
  color: var(--foreground);
}

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

/* Ensure all text elements have proper color */
.tiptap-content p,
.tiptap-content li,
.tiptap-content span,
.tiptap-content h1,
.tiptap-content h2,
.tiptap-content h3 {
  color: var(--foreground);
}

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

/* Focus state for editor container - disabled for cleaner look */
/* .tiptap-editor:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 0.2);
} */

/* Headings */
.tiptap-content h1 {
  font-size: 2em;
  font-weight: 700;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.2;
}

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

.tiptap-content h2 {
  font-size: 1.5em;
  font-weight: 600;
  margin-top: 1.25em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

.tiptap-content h2:first-child {
  margin-top: 0;
}

.tiptap-content h3 {
  font-size: 1.25em;
  font-weight: 600;
  margin-top: 1em;
  margin-bottom: 0.5em;
  line-height: 1.4;
}

.tiptap-content h3:first-child {
  margin-top: 0;
}

/* Paragraphs - compact spacing */
.tiptap-content p {
  margin-top: 0 !important;
  margin-bottom: 0.5em !important;
}

.tiptap-content p:last-child {
  margin-bottom: 0 !important;
}

/* Empty paragraphs should be smaller */
.tiptap-content p:empty,
.tiptap-content p br:only-child {
  margin-bottom: 0.25em !important;
}

/* Add spacing between different block types */
.tiptap-content h1 + p,
.tiptap-content h2 + p,
.tiptap-content h3 + p {
  margin-top: 0.25em !important;
}

/* Lists - compact spacing */
.tiptap-content ul {
  list-style-type: disc;
  padding-left: 1.5em;
  margin: 0.25em 0 0.5em 0 !important;
}

.tiptap-content ol {
  list-style-type: decimal;
  padding-left: 1.5em;
  margin: 0.25em 0 0.5em 0 !important;
}

.tiptap-content li {
  margin-top: 0.125em !important;
  margin-bottom: 0.125em !important;
  padding-left: 0.25em;
}

.tiptap-content li p {
  margin: 0 !important;
}

.tiptap-content ul ul {
  list-style-type: circle;
  margin: 0.5em 0;
}

.tiptap-content ul ul ul {
  list-style-type: square;
}

.tiptap-content ol ol {
  list-style-type: lower-alpha;
  margin: 0.5em 0;
}

.tiptap-content ol ol ol {
  list-style-type: lower-roman;
}

/* Blockquote */
.tiptap-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 1em;
  margin: 1em 0;
  color: var(--muted-foreground);
  font-style: italic;
}

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

/* Code */
.tiptap-content code {
  background: var(--muted);
  padding: 0.125em 0.25em;
  border-radius: 0.25rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
}

.tiptap-content pre {
  background: var(--muted);
  padding: 1em;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1em 0;
}

.tiptap-content pre code {
  background: none;
  padding: 0;
  font-size: 0.875em;
}

/* Links */
.tiptap-content a {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

.tiptap-content a:hover {
  text-decoration: none;
}

/* Horizontal rule */
.tiptap-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* Images */
.tiptap-content img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1em 0;
}

/* Tables */
.tiptap-content .tableWrapper {
  overflow-x: auto;
  margin: 1em 0;
}

.tiptap-content .tableWrapper table {
  margin: 0;
}

.tiptap-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  overflow: hidden;
  table-layout: fixed;
}

.tiptap-content th,
.tiptap-content td {
  border: 1px solid var(--border);
  padding: 0.75em 1em;
  text-align: left;
  vertical-align: top;
  position: relative;
  min-width: 100px;
}

.tiptap-content th {
  background: var(--muted);
  font-weight: 600;
}

.tiptap-content th p,
.tiptap-content td p {
  margin: 0;
}

/* Table resize handle */
.tiptap-content .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: -2px;
  width: 4px;
  background: var(--primary);
  cursor: col-resize;
  pointer-events: auto;
}

/* Selected table cells */
.tiptap-content .selectedCell:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: oklch(from var(--primary) l c h / 0.1);
  pointer-events: none;
}

/* Drag handle */
.drag-handle {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.drag-handle:hover {
  background: var(--muted);
}

/* Dragging state */
.dragging {
  opacity: 0.5;
}

/* Slash commands menu via tippy.js */
.tippy-box {
  background: transparent !important;
  border: none !important;
}

.tippy-content {
  padding: 0 !important;
}

/* Selection highlight */
.tiptap-content ::selection {
  background: oklch(from var(--primary) l c h / 0.2);
}

/* Toolbar button hover state */
.tiptap-editor [data-tiptap-action]:hover,
.tiptap-editor [data-dropdown-target="trigger"]:hover {
  background: var(--border);
}

/* Toolbar button active state */
.tiptap-editor [data-tiptap-action][aria-pressed="true"] {
  background: var(--border);
}

/* Table context - show table controls when inside table */
.tiptap-content table:focus-within {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

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

.tiptap-content ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 0.5em;
  padding-left: 0;
}

.tiptap-content ul[data-type="taskList"] li > label {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  user-select: none;
  margin-top: 0.2em;
}

.tiptap-content ul[data-type="taskList"] li > label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border);
  cursor: pointer;
  accent-color: var(--primary);
}

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

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

/* Nested task lists */
.tiptap-content ul[data-type="taskList"] ul[data-type="taskList"] {
  margin-left: 1.5em;
  margin-top: 0.25em;
  margin-bottom: 0.25em;
}

/* Highlight */
.tiptap-content mark {
  background-color: oklch(from var(--primary) l c h / 0.25);
  padding: 0.125em 0.25em;
  border-radius: 0.2em;
}

/* Superscript & Subscript */
.tiptap-content sup {
  font-size: 0.65em;
  vertical-align: 0.25em;
  line-height: 0;
}

.tiptap-content sub {
  font-size: 0.65em;
  vertical-align: -0.1em;
  line-height: 0;
}
