/* The note page: title, the Crepe editor themed onto our tokens, the conflict bar. */
:is(.doc, .beside-doc) .milkdown {
  --crepe-color-background: transparent;
  --crepe-color-on-background: var(--text);
  --crepe-color-surface: var(--surface-2);
  --crepe-color-surface-low: var(--surface-3);
  --crepe-color-on-surface: var(--text);
  --crepe-color-on-surface-variant: var(--text-2);
  --crepe-color-outline: var(--text-3);
  --crepe-color-primary: var(--accent);
  --crepe-color-secondary: var(--accent-soft);
  --crepe-color-on-secondary: var(--text);
  --crepe-color-inverse: var(--text);
  --crepe-color-on-inverse: var(--surface-0);
  --crepe-color-inline-code: var(--ic-orange);
  --crepe-color-error: var(--danger);
  --crepe-color-hover: var(--surface-3);
  --crepe-color-selected: var(--select);
  --crepe-color-inline-area: var(--surface-3);
  --crepe-base-font-size: var(--fs-body);
  --crepe-font-title: var(--font-ui);
  --crepe-font-default: var(--font-ui);
  --crepe-font-code: var(--font-mono);
  --crepe-shadow-1: 0 1px 2px rgb(0 0 0 / 0.25);
  --crepe-shadow-2: var(--shadow-pop);
}

.doc-title {
  width: 100%;
  margin: 0 0 var(--sp-4);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 700 var(--fs-h1) / 1.25 var(--font-ui);
  letter-spacing: -0.02em;
  outline: none;
}

.doc-title::placeholder {
  color: var(--text-3);
}

/* Crepe pads its editor for a centred page; here the text fills the pane. */
:is(.doc, .beside-doc) .milkdown .ProseMirror {
  padding: var(--sp-4) 0 30vh;
  line-height: 1.65;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror h1,
:is(.doc, .beside-doc) .milkdown .ProseMirror h2,
:is(.doc, .beside-doc) .milkdown .ProseMirror h3 {
  margin: 1.4em 0 0.4em;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror h1 {
  font-size: 24px;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror h2 {
  font-size: 20px;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror h3 {
  font-size: 17px;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror > :first-child {
  margin-top: 0;
}

:is(.doc, .beside-doc) .milkdown .ProseMirror a {
  color: var(--accent);
}

:is(.doc, .beside-doc) .milkdown .milkdown-code-block {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-1);
}

.conflict {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  padding: var(--sp-4) var(--sp-6);
  border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface-2));
}

.conflict span {
  flex: 1;
}

/* File nodes: PDFs and images shown in the page, other files as a download card. */
.file-view {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  min-height: calc(100vh - 140px);
}

.file-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4) var(--sp-6);
}

.file-head .doc-title {
  flex: 1;
  width: auto;
  margin: 0;
  overflow-wrap: anywhere;
}

.file-actions {
  display: flex;
  gap: var(--sp-3);
}

.file-frame {
  flex: 1;
  width: 100%;
  min-height: 70vh;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}

.file-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-md);
  align-self: flex-start;
}

.file-card {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-7);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  color: var(--text-2);
}

.file-card .i {
  width: 28px;
  height: 28px;
  color: var(--text-3);
}

.doc-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  min-height: 24px;
  margin-bottom: var(--sp-5);
}

.tag-add {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 22px;
  padding: 0 var(--sp-3);
  border-radius: 999px;
  color: var(--text-3);
  font-size: var(--fs-sm);
}

.tag-add:hover {
  background: var(--surface-3);
  color: var(--text);
}

.tag-add .i {
  width: 13px;
  height: 13px;
}

/* Folding headings (view-only) */
.doc .milkdown .ProseMirror .fold-hidden {
  display: none;
}

.doc .milkdown .ProseMirror :is(h1, h2, h3, h4, h5, h6) {
  position: relative;
}

.fold-toggle {
  position: absolute;
  top: 50%;
  left: -22px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  opacity: 0;
  cursor: pointer;
  transform: translateY(-50%);
  transition: opacity var(--t-fast), transform var(--t-fast);
}

/* a chevron drawn in CSS: pointing down when open, right when folded */
.fold-toggle::before {
  content: "";
  position: absolute;
  inset: 5px 6px 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.fold-toggle[aria-expanded="false"]::before {
  transform: rotate(-45deg);
}

.fold-toggle:hover {
  background: var(--surface-3);
  color: var(--text);
}

.ProseMirror :is(h1, h2, h3, h4, h5, h6):hover > .fold-toggle,
.ProseMirror .is-folded > .fold-toggle,
.fold-toggle:focus-visible {
  opacity: 1;
}

/* a folded heading says there is more under it */
.doc .milkdown .ProseMirror .is-folded::after {
  content: " …";
  color: var(--text-3);
  font-weight: 400;
}

.beside-doc .fold-toggle {
  display: none;
}
