/*
 * Rich-text styling for the TipTap-powered ActionText editor and the rendered
 * output it produces. Themed against the app's Nord palette. This file is
 * auto-included by ActionText's engine.
*/

/* ---- Editor frame ---------------------------------------------------- */

.tiptap {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  padding: 0.375rem 0.375rem 0.5rem;
}

.tiptap:has(.tiptap__editor .ProseMirror:focus) {
/*   border-color: var(--accent); */
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.tiptap__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.tiptap__divider {
  display: inline-block;
  width: 1px;
  height: 1.25rem;
  background: var(--border);
  margin: 0 0.125rem;
}

.tiptap__btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.875rem;
  min-width: 1.875rem;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;

  &:hover {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--text);
  }

  &:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }

  &.is-active {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    border-color: color-mix(in srgb, var(--accent) 60%, transparent);
    color: var(--text);
  }

  &--bold   { font-weight: 700; }
  &--italic { font-style:  italic; }
}

.tiptap__editor {
/*   padding: 0.375rem 0.5rem; */
}

.tiptap__editor .ProseMirror {
  min-height: 10rem;
  outline: none;
  color: var(--text);
  border: none;
  padding: 0 0.375rem 0.5rem;

  & > * + * { margin-top: 0.5em; }

  /* TipTap's "type something" placeholder. */
  p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
    color: var(--text-dim);
  }
}

/* ---- Rendered output (action-text/_content.html.erb wraps in .rich-text) - */

.rich-text {
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
  color: var(--text);
}

.rich-text > * + * { margin-top: 0.5em; }
.rich-text > :first-child { margin-top: 0; }

.rich-text h2,
.rich-text h3 { line-height: 1.2; margin: 1em 0 0.5em; letter-spacing: -0.01em; }
.rich-text h2:first-child,
.rich-text h3:first-child { margin-top: 0; }
.rich-text h2 { font-size: 1.25em; }
.rich-text h3 { font-size: 1.1em;  }

.rich-text p { margin: 0.5em 0; }
.rich-text a { color: var(--accent); }

.rich-text blockquote {
  border-left: 0.25em solid var(--border);
  margin: 0.75em 0 0.75em 0.25em;
  padding-left: 0.75em;
  color: var(--text-muted);
}

.rich-text ul,
.rich-text ol { margin: 0.5em 0 0.5em 1.25em; padding: 0; }
.rich-text li { margin: 0.125em 0; }

.rich-text code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--surface-raised) 70%, transparent);
  padding: 0.1em 0.3em;
  border-radius: 0.25rem;
}

.rich-text pre {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  padding: 0.625em 0.75em;
  white-space: pre;
  background: var(--surface-raised);
  border-radius: 0.375rem;
  overflow-x: auto;
}

.rich-text img { max-width: 100%; height: auto; }

/* The editor renders the same content visually, so apply the rendered-output
   typography inside the ProseMirror view too. */
.tiptap__editor .ProseMirror h2 { font-size: 1.25em; line-height: 1.2; letter-spacing: -0.01em; }
.tiptap__editor .ProseMirror h3 { font-size: 1.1em;  line-height: 1.2; letter-spacing: -0.01em; }
.tiptap__editor .ProseMirror blockquote {
  border-left: 0.25em solid var(--border);
  margin-left: 0.25em;
  padding-left: 0.75em;
  color: var(--text-muted);
}
.tiptap__editor .ProseMirror ul,
.tiptap__editor .ProseMirror ol { margin-left: 1.25em; padding: 0; }
.tiptap__editor .ProseMirror code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--surface-raised) 70%, transparent);
  padding: 0.1em 0.3em;
  border-radius: 0.25rem;
}
