/*
  The base rules of ProseMirror, copied from prosemirror-view/style/prosemirror.css (MIT, Copyright (C) 2015-2017 Marijn Haverbeke and others).
  TipTap would inject them into a <style> element; injectCSS is off so that a strict style-src stays possible, and the page serves them
  here. editor/test/bundle.test.js compares this block with the package, rule by rule, so an upgrade that changes them fails a test.
*/

.ProseMirror {
  position: relative;
}

.ProseMirror {
  word-wrap: break-word;
  white-space: pre-wrap;
  white-space: break-spaces;
  -webkit-font-variant-ligatures: none;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
}

.ProseMirror pre {
  white-space: pre-wrap;
}

.ProseMirror li {
  position: relative;
}

.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection *::-moz-selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }

/* See https://code.haverbeke.berlin/prosemirror/prosemirror/issues/1421#issuecomment-1759320191 */
.ProseMirror [draggable][contenteditable=false] { user-select: text }

.ProseMirror-selectednode {
  outline: 2px solid #8cf;
}

/* Make sure li selections wrap around markers */

li.ProseMirror-selectednode {
  outline: none;
}

li.ProseMirror-selectednode:after {
  content: "";
  position: absolute;
  left: -32px;
  right: -2px; top: -2px; bottom: -2px;
  border: 2px solid #8cf;
  pointer-events: none;
}

/* Protect against generic img rules */

img.ProseMirror-separator {
  display: inline !important;
  border: none !important;
  margin: 0 !important;
}

/*
  The editor's stylesheet (NT-030), served by the instance next to notetaking.css. The editor's script builds the
  editing surface (.ProseMirror) inside .nt-editor-host, so these rules cannot be scoped CSS of a component; they use the
  design tokens of notetaking.css only. TipTap does not inject a <style> element of its own (injectCSS is off), so a
  strict style-src policy can stay as strict as NT-026 wants it.
*/

.nt-editor-host {
    min-height: 100%;
    padding: 1rem 1.25rem 4rem;
}

.nt-editor-host .ProseMirror {
    max-width: 48rem;
    min-height: 12rem;
    margin: 0 auto;
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0;
    line-height: 1.6;
}

/* The surface is a focus target of its own (the skip link ends before it and the next Tab lands here): it shows it. */
.nt-editor-host .ProseMirror:focus-visible {
    outline: 2px solid var(--nt-accent);
    outline-offset: 6px;
}

.nt-editor-host .ProseMirror[contenteditable="false"] {
    color: var(--nt-text-muted);
}

.nt-editor-host .ProseMirror p {
    margin: 0 0 0.75em;
}

.nt-editor-host .ProseMirror h1,
.nt-editor-host .ProseMirror h2,
.nt-editor-host .ProseMirror h3,
.nt-editor-host .ProseMirror h4 {
    margin: 1.2em 0 0.4em;
    line-height: 1.25;
}

.nt-editor-host .ProseMirror h1 { font-size: 1.75rem; }
.nt-editor-host .ProseMirror h2 { font-size: 1.45rem; }
.nt-editor-host .ProseMirror h3 { font-size: 1.2rem; }
.nt-editor-host .ProseMirror h4 { font-size: 1.05rem; }

.nt-editor-host .ProseMirror > :first-child {
    margin-top: 0;
}

.nt-editor-host .ProseMirror ul,
.nt-editor-host .ProseMirror ol {
    margin: 0 0 0.75em;
    padding-left: 1.6em;
}

.nt-editor-host .ProseMirror li > p {
    margin: 0 0 0.25em;
}

.nt-editor-host .ProseMirror blockquote {
    margin: 0 0 0.75em;
    padding-left: 1rem;
    border-left: 3px solid var(--nt-border);
    color: var(--nt-text-muted);
}

.nt-editor-host .ProseMirror code {
    padding: 0.1em 0.3em;
    border-radius: 3px;
    background: var(--nt-hover);
    font-family: var(--nt-font-mono);
    font-size: 0.92em;
}

.nt-editor-host .ProseMirror pre {
    margin: 0 0 0.75em;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    border-radius: var(--nt-radius);
    background: var(--nt-bg-sidebar);
    border: 1px solid var(--nt-border);
    font-family: var(--nt-font-mono);
    font-size: 0.92em;
    white-space: pre;
}

.nt-editor-host .ProseMirror pre code {
    padding: 0;
    background: none;
}

.nt-editor-host .ProseMirror hr {
    margin: 1.25rem 0;
    border: 0;
    border-top: 1px solid var(--nt-border);
}

.nt-editor-host .ProseMirror img {
    max-width: 100%;
    height: auto;
}

/* Task lists: the checkbox and the text side by side. NT-031 makes the checkbox toggle with one click. */
.nt-editor-host .ProseMirror ul[data-type="taskList"] {
    padding-left: 0.25rem;
    list-style: none;
}

.nt-editor-host .ProseMirror ul[data-type="taskList"] > li {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.nt-editor-host .ProseMirror ul[data-type="taskList"] > li > label {
    flex: 0 0 auto;
    padding-top: 0.2em;
    user-select: none;
}

.nt-editor-host .ProseMirror ul[data-type="taskList"] > li > div {
    flex: 1 1 auto;
    min-width: 0;
}

.nt-editor-host .ProseMirror li[data-checked="true"] > div {
    color: var(--nt-text-muted);
    text-decoration: line-through;
}

.nt-editor-host .ProseMirror table {
    width: 100%;
    margin: 0 0 0.75em;
    border-collapse: collapse;
    table-layout: fixed;
}

.nt-editor-host .ProseMirror th,
.nt-editor-host .ProseMirror td {
    min-width: 3rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--nt-border);
    vertical-align: top;
}

.nt-editor-host .ProseMirror th {
    background: var(--nt-bg-sidebar);
    text-align: left;
}

.nt-editor-host .ProseMirror a {
    color: var(--nt-accent-strong);
}

/* Visible selection of a whole node (an image, a rule). */
.nt-editor-host .ProseMirror .ProseMirror-selectednode {
    outline: 2px solid var(--nt-accent);
}

.nt-editor-host .ProseMirror-gapcursor {
    display: none;
    position: relative;
    pointer-events: none;
}

.nt-editor-host .ProseMirror-gapcursor::after {
    content: "";
    display: block;
    position: absolute;
    top: -2px;
    width: 1.25rem;
    border-top: 1px solid var(--nt-text);
    animation: nt-caret 1.1s steps(2, start) infinite;
}

.nt-editor-host .ProseMirror.ProseMirror-focused .ProseMirror-gapcursor {
    display: block;
}

@keyframes nt-caret {
    to {
        visibility: hidden;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nt-editor-host .ProseMirror-gapcursor::after {
        animation: none;
    }
}

.nt-editor-host .ProseMirror-dropcursor {
    background: var(--nt-accent);
}
