/**
 * Shared TipTap editor + document-page styles.
 * Used by: client (editor) via <link href="/tiptap.css"> and server (PDF export) via fs read + inject.
 * Vars use fallbacks so PDF (no globals.css) still renders correctly.
 */
:root {
  --document-bg: 0 0% 100%;
  --document-shadow: 220 14% 80%;
  --font-document: "Crimson Pro", Georgia, serif;
  --doc-title-pt: 16pt;
  --doc-h1-pt: 16pt;
  --doc-h2-pt: 14pt;
  --doc-h3-pt: 12pt;
  --doc-body-pt: 10pt;
  --doc-caption-pt: 8.5pt;
  --doc-line-body: 1.5;
  --doc-line-heading: 1.25;
  --doc-line-list: 1.45;
  --foreground: 222.2 84% 4.9%;
  --primary: 16 95% 58%;
  --border: 214.3 31.8% 91.4%;
  --muted: 210 40% 96%;
  --muted-foreground: 215.4 16.3% 46.9%;
}

.document-page {
  background-color: hsl(var(--document-bg));
  box-shadow: 0 1px 3px hsl(var(--document-shadow) / 0.1),
    0 4px 6px hsl(var(--document-shadow) / 0.1),
    0 10px 20px hsl(var(--document-shadow) / 0.15);
}

.a4-page {
  width: 210mm;
  min-height: 297mm;
}

.document-a4 {
  width: 794px;
  min-height: 1123px;
  box-sizing: border-box;
}

/* ==========================================================================
   TipTap Editor – Professional document styling
   ========================================================================== */

.tiptap-editor {
  outline: none;
  font-family: var(--font-document);
  font-size: var(--doc-body-pt);
  line-height: var(--doc-line-body);
  color: hsl(var(--foreground));
  word-wrap: break-word;
}

.tiptap-editor::selection {
  background: hsl(var(--primary) / 0.2);
}

.tiptap-editor > :first-child {
  margin-top: 0;
}

.tiptap-editor img {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  height: auto;
}

.tiptap-editor [data-resize-container] {
  display: inline-flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  vertical-align: middle;
  min-width: 0;
  max-width: 100%;
}

.tiptap-editor [data-resize-container] + [data-resize-container] {
  margin-left: 0.5rem;
}

.tiptap-editor [data-resize-wrapper] {
  display: inline-block !important;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
  min-width: 0;
}

.tiptap-editor [data-resize-container] img {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.tiptap-editor [data-resize-wrapper] + [data-resize-wrapper] {
  margin-left: 0.5rem;
}

.tiptap-editor [data-resize-handle] {
  position: absolute;
  background: hsl(220 10% 40%);
  border: 1px solid hsl(0 0% 100%);
  border-radius: 2px;
  z-index: 10;
}

.tiptap-editor [data-resize-handle]:hover {
  background: hsl(220 10% 25%);
}

.tiptap-editor [data-resize-handle="top-left"],
.tiptap-editor [data-resize-handle="top-right"],
.tiptap-editor [data-resize-handle="bottom-left"],
.tiptap-editor [data-resize-handle="bottom-right"] {
  width: 8px;
  height: 8px;
}

.tiptap-editor [data-resize-handle="top-left"] {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.tiptap-editor [data-resize-handle="top-right"] {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.tiptap-editor [data-resize-handle="bottom-left"] {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

.tiptap-editor [data-resize-handle="bottom-right"] {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}

.tiptap-editor [data-resize-state="true"] [data-resize-wrapper] {
  outline: 1px solid hsl(var(--border));
  border-radius: 2px;
}

.tiptap-editor hr {
  border: none;
  border-top: 1px solid currentColor;
  opacity: 0.5;
  cursor: pointer;
  height: 8px;
}

.tiptap-editor a {
  color: #1565c0;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}

.tiptap-editor a:hover {
  color: #0d47a1;
  text-decoration-thickness: 1.5px;
}

.tiptap-editor p {
  line-height: var(--doc-line-body);
  font-size: var(--doc-body-pt);
  margin: 0 0 0.5em 0;
}

.tiptap-editor p[style*="margin"] {
  line-height: var(--doc-line-body) !important;
  font-size: var(--doc-body-pt) !important;
}

.tiptap-editor h1,
.tiptap-editor h2,
.tiptap-editor h3 {
  font-family: var(--font-document);
  color: hsl(var(--foreground));
  line-height: var(--doc-line-heading);
  font-weight: 600;
}

.tiptap-editor h1 {
  font-size: var(--doc-h1-pt) !important;
  font-weight: 700;
  margin-top: 0;
  letter-spacing: -0.02em;
}

.tiptap-editor h2 {
  font-size: var(--doc-h2-pt) !important;
  margin-top: 1em;
}

.tiptap-editor h3 {
  font-size: var(--doc-h3-pt) !important;
  margin-top: 0.85em;
}

.tiptap-editor ul,
.tiptap-editor ol {
  margin-top: 0;
  margin-bottom: 0.4em;
  padding-left: 1.75em;
  list-style: none;
  font-size: var(--doc-body-pt);
}

.tiptap-editor ul[style*="margin"],
.tiptap-editor ol[style*="margin"] {
  margin-top: 0 !important;
  margin-bottom: 0.4em !important;
  padding-left: 1.75em !important;
}

.tiptap-editor ul > li {
  position: relative;
  padding-left: 0.4em;
  margin-bottom: 0.3em;
  line-height: var(--doc-line-list);
}

.tiptap-editor ul > li::before {
  content: "•";
  position: absolute;
  left: -1em;
  top: 0;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
}

.tiptap-editor ul > li[style*="margin"],
.tiptap-editor ol > li[style*="margin"] {
  margin-top: 0 !important;
  margin-bottom: 0.2em !important;
}

.tiptap-editor ol {
  counter-reset: list-counter;
}

.tiptap-editor ol > li {
  counter-increment: list-counter;
  position: relative;
  padding-left: 0.5em;
  line-height: var(--doc-line-list);
}

.tiptap-editor ol > li::before {
  content: counter(list-counter) ".";
  position: absolute;
  left: -1.75em;
  min-width: 1.75em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--muted-foreground));
  font-weight: 500;
}

.tiptap-editor blockquote {
  margin: 0.75em 0;
  padding: 0.4em 0 0.4em 0.9em;
  border-left: 3px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
  color: hsl(var(--muted-foreground));
  font-style: italic;
  border-radius: 0 3px 3px 0;
  font-size: var(--doc-body-pt);
  line-height: var(--doc-line-body);
}

.tiptap-editor table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: var(--doc-body-pt);
  line-height: var(--doc-line-body);
}

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

.tiptap-editor th {
  background: hsl(var(--muted) / 0.6);
  font-weight: 600;
  color: hsl(var(--foreground));
}

.tiptap-editor tr:nth-child(even) td {
  background: hsl(var(--muted) / 0.25);
}

.tiptap-editor ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
}

.tiptap-editor ul[data-type="taskList"] > li {
  display: flex;
  align-items: flex-start;
  gap: 0.5em;
  padding-left: 0;
  margin-bottom: 0.35em;
  line-height: var(--doc-line-list);
}

.tiptap-editor ul[data-type="taskList"] > li::before {
  content: none;
}

.tiptap-editor ul[data-type="taskList"] li input[type="checkbox"] {
  margin-top: 0.35em;
  flex-shrink: 0;
  cursor: pointer;
}

.tiptap-editor [data-type="caption"],
.tiptap-editor .caption,
.tiptap-editor small {
  font-size: var(--doc-caption-pt);
  line-height: 1.4;
  color: hsl(var(--muted-foreground));
}

.tiptap-editor .is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  pointer-events: none;
  color: hsl(var(--muted-foreground));
  opacity: 0.7;
  font-size: var(--doc-body-pt);
}

.link-dialog [data-slot="input"] {
  font-family: inherit;
}

.link-dialog .grid.gap-4 {
  gap: 1rem;
}

.link-dialog label {
  font-weight: 500;
  color: hsl(var(--foreground));
}

/* --- Print / PDF: A4 page breaks at 297mm --- */
@media print {
  @page {
    size: A4;
    margin: 0;
  }
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
  html,
  body {
    margin: 0;
    padding: 0;
    width: 210mm;
    min-height: 100%;
    font-family: var(--font-document);
    color: #1a1a1a;
  }
  .document-page.document-a4 {
    width: 210mm;
    min-height: 297mm;
    padding: 64px;
    background: #fff;
    box-shadow: none;
  }
}
