/* ═══════════════════════════════════════════════════════════════════════════
   COMPOSE — Editor
   The writing surface. Premium, quiet, focused.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Scroll container ────────────────────────────────────────────────── */
#editor-scroll {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Canvas is always the brightest surface — content is the light */
  background: var(--bg-canvas);
}

/* ── Paper — full-surface, no card, clean ────────────────────────────── */
#editor-paper {
  width: 100%;
  max-width: calc(var(--ed-line-width) + 80px);
  padding: 56px 40px 80px;
  flex: 1;
  min-height: calc(100dvh - var(--topbar-h) - var(--toolbar-h));
  background: var(--bg-canvas);
}

/* ── Desktop: generous centred padding ───────────────────────────────── */
@media (min-width: 768px) {
  #editor-scroll { padding: 0 var(--s-generous); }
  #editor-paper  {
    max-width: calc(var(--ed-line-width) + 96px);
    padding: 64px 48px 96px;
    min-height: auto;
  }
}

/* ── Mobile: compact padding, no artificial min-height ───────────────── */
@media (max-width: 767px) {
  #editor-scroll {
    padding: 0;
    /* Allow scroll area to fill canvas (canvas has bottom padding for toolbar) */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #editor-paper {
    padding: 24px 20px 48px;
    max-width: 100%;
    /* Remove desktop min-height — flex layout fills the space correctly */
    min-height: unset;
  }
}

/* ── ProseMirror root ────────────────────────────────────────────────── */
.ProseMirror {
  font-family: var(--ed-body-font);
  font-size: var(--ed-font-size);
  line-height: var(--ed-line-height);
  color: var(--ed-text);
  max-width: var(--ed-line-width);
  margin: 0 auto;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

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

/* ── Headings ────────────────────────────────────────────────────────── */
.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
  font-family: var(--ed-heading-font);
  color: var(--ed-text);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-top: 1.8em;
  margin-bottom: 0.5em;
}

.ProseMirror h1 { font-size: 2em;    font-weight: 700; margin-top: 0; }
.ProseMirror h2 { font-size: 1.5em;  font-weight: 600; }
.ProseMirror h3 { font-size: 1.25em; font-weight: 600; }
.ProseMirror h4 { font-size: 1.1em;  font-weight: 600; }
.ProseMirror h5 { font-size: 1em;    font-weight: 600; }
.ProseMirror h6 { font-size: 0.9em;  font-weight: 600; color: var(--text-sec); }

/* ── Paragraphs ──────────────────────────────────────────────────────── */
.ProseMirror p { margin-bottom: 0.8em; }
.ProseMirror p:last-child { margin-bottom: 0; }

/* ── Lists ───────────────────────────────────────────────────────────── */
.ProseMirror ul,
.ProseMirror ol {
  padding-left: 1.6em;
  margin-bottom: 0.8em;
}

.ProseMirror li { margin-bottom: 0.25em; }
.ProseMirror li p { margin-bottom: 0.2em; }

/* ── Blockquote ──────────────────────────────────────────────────────── */
.ProseMirror blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.2em 0;
  padding: 0.2em 0 0.2em 1.2em;
  color: var(--text-sec);
  font-style: italic;
}

/* ── Code ────────────────────────────────────────────────────────────── */
.ProseMirror code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--fill-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.1em 0.4em;
}

.ProseMirror pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--fill-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 1em 1.2em;
  overflow-x: auto;
  margin-bottom: 1em;
}

.ProseMirror pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

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

/* ── Links ───────────────────────────────────────────────────────────── */
.ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ProseMirror a:hover { text-decoration-thickness: 2px; }

/* ── Strong / em ─────────────────────────────────────────────────────── */
.ProseMirror strong { font-weight: 700; }
.ProseMirror em { font-style: italic; }
.ProseMirror s { text-decoration: line-through; color: var(--text-sec); }
.ProseMirror u { text-decoration: underline; text-underline-offset: 2px; }

/* ── Highlight ───────────────────────────────────────────────────────── */
.ProseMirror mark {
  background: rgba(var(--accent-rgb), 0.2);
  color: inherit;
  border-radius: 2px;
  padding: 0.05em 0.1em;
}

/* ── Images ──────────────────────────────────────────────────────────── */
.ProseMirror .prose-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--r-md);
  margin: 1.2em auto;
  cursor: pointer;
}

/* When left/right aligned at non-full width, float to reflow text */
.ProseMirror .prose-image.align-left[style*="max-width"] {
  float: left;
  margin: 0.4em 1.4em 0.8em 0;
  display: inline-block;
}
.ProseMirror .prose-image.align-right[style*="max-width"] {
  float: right;
  margin: 0.4em 0 0.8em 1.4em;
  display: inline-block;
}
/* Center is always block (no float) */
.ProseMirror .prose-image.align-center {
  float: none;
  margin: 1.2em auto;
  display: block;
}
/* Full-width left/right: no float */
.ProseMirror .prose-image.align-left:not([style*="max-width"])  { float: none; margin-right: auto; margin-left: 0; }
.ProseMirror .prose-image.align-right:not([style*="max-width"]) { float: none; margin-left: auto; margin-right: 0; }

/* Clearfix after floated images */
.ProseMirror p:has(+ p) { overflow: hidden; }
.ProseMirror::after { content: ''; display: table; clear: both; }

/* Selected image ring */
.ProseMirror .ProseMirror-selectednode .prose-image,
.ProseMirror .prose-image.ProseMirror-selectednode {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Tables ──────────────────────────────────────────────────────────── */
.ProseMirror table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1em;
  font-size: 0.9em;
}

.ProseMirror th,
.ProseMirror td {
  border: 1px solid var(--border-strong);
  padding: 0.5em 0.75em;
  vertical-align: top;
  text-align: left;
}

.ProseMirror th {
  background: var(--fill-subtle);
  font-weight: 600;
}

.ProseMirror .selectedCell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(var(--accent-rgb), 0.14);
  pointer-events: none;
}

.ProseMirror td, .ProseMirror th { position: relative; }

.ProseMirror .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: var(--accent);
  cursor: col-resize;
  z-index: 10;
}

/* ── Citation nodes ──────────────────────────────────────────────────── */
.citation-ref {
  color: var(--accent);
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  cursor: pointer;
  font-family: var(--font-ui);
}

.citation-ref:hover { text-decoration: underline; }

/* ── Notes section ───────────────────────────────────────────────────── */
#notes-section {
  max-width: var(--ed-line-width);
  margin: 3em auto 0;
  padding-top: 0;
}

/* The top rule only appears when there IS content */
#notes-section:not(:empty) {
  border-top: 1px solid var(--border);
  padding-top: 1.5em;
}

#notes-section:empty { display: none; }

.notes-block { margin-bottom: 1.2em; }

.notes-block-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .8em;
  font-family: var(--font-ui);
}

/* Separator between Footnotes and Endnotes blocks */
.notes-separator {
  height: 1px;
  background: var(--border);
  margin: 1.2em 0;
}

.note-item {
  font-family: var(--ed-body-font);
  font-size: 0.82em;
  color: var(--text-sec);
  line-height: 1.65;
  margin-bottom: 0.7em;
  display: flex;
  gap: 0.5em;
}

.note-item .note-number {
  color: var(--accent);
  font-size: 0.9em;
  flex-shrink: 0;
  min-width: 1.5em;
  cursor: pointer;
}
.note-item .note-number:hover { text-decoration: underline; }

/* ── Selection ───────────────────────────────────────────────────────── */
.ProseMirror ::selection {
  background: rgba(var(--accent-rgb), 0.2);
}

/* ── Cursor ──────────────────────────────────────────────────────────── */
.ProseMirror-focused { caret-color: var(--accent); }

/* ── Drag and drop ───────────────────────────────────────────────────── */
.ProseMirror .ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
}

.ProseMirror .ProseMirror-gapcursor::after {
  content: '';
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 2px solid var(--text);
}

.ProseMirror-focused .ProseMirror-gapcursor { display: block; }

/* ── Search highlight — CSS Custom Highlight API ─────────────────────── */
/* These ::highlight() pseudo-elements are painted by the browser as a
   separate layer. Zero DOM mutations inside ProseMirror. */
::highlight(search-results) {
  background-color: rgba(var(--accent-rgb), 0.22);
  color: inherit;
}

::highlight(search-current) {
  background-color: rgba(var(--accent-rgb), 0.55);
  color: inherit;
}

/* ════════════════════════════════════════════════════════════════════════
   PRINT / PDF EXPORT — strips all app chrome, formats document only
   ════════════════════════════════════════════════════════════════════════ */
@media print {
  /* Hide everything except the document content */
  #sidebar,
  #topbar,
  #toolbar-row,
  #toolbar-mobile,
  #stats-popover,
  #link-popover,
  #citation-sheet,
  #overlay,
  #support-banner,
  .tb-tooltip,
  [role="toolbar"] {
    display: none !important;
  }

  /* Reset the layout */
  html, body, #app, #main, #body, #canvas {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #editor-scroll {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
  }

  #editor-paper {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: white !important;
  }

  #editor {
    padding: 0 !important;
    min-height: auto !important;
  }

  /* Typography — clean for print */
  .ProseMirror {
    font-size: 11pt !important;
    line-height: 1.6 !important;
    color: #000 !important;
    max-width: 100% !important;
  }

  .ProseMirror h1 { font-size: 20pt !important; margin: 0 0 12pt !important; }
  .ProseMirror h2 { font-size: 16pt !important; margin: 16pt 0 8pt !important; }
  .ProseMirror h3 { font-size: 13pt !important; margin: 12pt 0 6pt !important; }
  .ProseMirror p  { margin: 0 0 8pt !important; orphans: 3; widows: 3; }

  .ProseMirror a { color: #000 !important; text-decoration: underline !important; }

  /* Avoid breaking inside these */
  .ProseMirror blockquote,
  .ProseMirror pre,
  .ProseMirror table { page-break-inside: avoid; }

  /* Page margins */
  @page {
    margin: 2cm 2.5cm;
    size: A4;
  }

  /* Hide search highlights (CSS Custom Highlight API) */
  ::highlight(search-results),
  ::highlight(search-current) {
    background-color: transparent !important;
    color: inherit !important;
  }

  /* Notes section */
  #notes-section {
    border-top: 1px solid #ccc !important;
    margin-top: 24pt !important;
    padding-top: 12pt !important;
    font-size: 9pt !important;
    color: #333 !important;
  }
}

