/*
 * styles-block-flush.css
 * ──────────────────────────────────────────────────────────
 * Single source of truth: ensures document blocks render flush
 * (zero gap) in Client View, portal, print, and any other
 * non-editor rendering context.
 *
 * IMPORTANT: All rules use :not(.ql-editor) or :not(.ql-editor *)
 * guards so they NEVER interfere with the live Quill editor.
 *
 * DO NOT EDIT styles-master.css or styles-gmail.css to "fix"
 * block gaps — add overrides HERE so they stay in one place.
 * ──────────────────────────────────────────────────────────
 */

/*
 * The :where() wrapper keeps specificity at 0 for the guard,
 * while the inner selector + !important ensure the override wins
 * against styles-master.css / styles-gmail.css.
 *
 * The guard: blocks INSIDE .ql-editor are skipped (editor keeps
 * its own margin/padding/border for editing UX).
 */

/* ── Wrapper divs: invisible, zero-chrome ── */
:where(:not(.ql-editor)) > .line-items-embed {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  display: block;
}

:where(:not(.ql-editor)) > .line-items-embed > .text-block-static {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  border-radius: 0 !important;
}

:where(:not(.ql-editor)) > .line-items-static,
:where(:not(.ql-editor)) > .line-items-embed > .line-items-static {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* ── Adjacent blocks: no gap ── */
:where(:not(.ql-editor)) > .line-items-embed + .line-items-embed {
  margin-top: 0 !important;
}

/* ── Visual card (.text-block-shell): flush corners, keep padding ── */
:where(:not(.ql-editor)) .text-block-shell {
  border-radius: 0 !important;
  margin: 0 !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

/* ── Quill editor wrapper: zero-chrome when it leaks into preview ── */
/* Exclude #prefEmailSignatureEditor (My Preferences signature mini-editor). */
:where(:not(#quillEditor):not(#prefEmailSignatureEditor)) > .ql-editor,
:where(:not(#quillEditor)) > .ql-container:not(#prefEmailSignatureEditor) > .ql-editor {
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

/* ── Spacer paragraphs: hide only Quill sentinels next to composer blocks ── */
:where(:not(.ql-editor)) > .line-items-embed + p:empty:has(+ .line-items-embed),
:where(:not(.ql-editor)) > .line-items-static + p:empty:has(+ .line-items-static),
:where(:not(.ql-editor)) > .line-items-embed + p:empty:has(+ .line-items-static),
:where(:not(.ql-editor)) > .line-items-static + p:empty:has(+ .line-items-embed),
:where(:not(.ql-editor)) > .line-items-embed + p:has(> br:only-child):has(+ .line-items-embed),
:where(:not(.ql-editor)) > .line-items-static + p:has(> br:only-child):has(+ .line-items-static),
:where(:not(.ql-editor)) > .line-items-embed + p:has(> br:only-child):has(+ .line-items-static),
:where(:not(.ql-editor)) > .line-items-static + p:has(> br:only-child):has(+ .line-items-embed),
:where(:not(.ql-editor)) > .line-items-embed + p:empty:last-child,
:where(:not(.ql-editor)) > .line-items-static + p:empty:last-child,
:where(:not(.ql-editor)) > .line-items-embed + p:has(> br:only-child):last-child,
:where(:not(.ql-editor)) > .line-items-static + p:has(> br:only-child):last-child,
:where(:not(.ql-editor)) > p:empty:first-child:has(+ .line-items-embed),
:where(:not(.ql-editor)) > p:empty:first-child:has(+ .line-items-static),
:where(:not(.ql-editor)) > p:has(> br:only-child):first-child:has(+ .line-items-embed),
:where(:not(.ql-editor)) > p:has(> br:only-child):first-child:has(+ .line-items-static) {
  display: none !important;
}
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:empty:has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:empty:has(+ .line-items-static),
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:empty:has(+ .line-items-static),
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:empty:has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:has(> br:only-child):has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:has(> br:only-child):has(+ .line-items-static),
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:has(> br:only-child):has(+ .line-items-static),
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:has(> br:only-child):has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:empty:last-child,
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:empty:last-child,
:where(:not(#quillEditor)) .ql-editor > .line-items-embed + p:has(> br:only-child):last-child,
:where(:not(#quillEditor)) .ql-editor > .line-items-static + p:has(> br:only-child):last-child,
:where(:not(#quillEditor)) .ql-editor > p:empty:first-child:has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > p:empty:first-child:has(+ .line-items-static),
:where(:not(#quillEditor)) .ql-editor > p:has(> br:only-child):first-child:has(+ .line-items-embed),
:where(:not(#quillEditor)) .ql-editor > p:has(> br:only-child):first-child:has(+ .line-items-static) {
  display: none !important;
}

/* ── Read-only prose rhythm (client view, portal, print body) ─────────────────
   Match the Quill editor exactly: paragraphs have NO margin-top / margin-bottom so adjacent
   <p>text</p> stack tightly. Vertical rhythm comes from blank <p><br></p> lines the user
   inserts (portal/print inline styles give those min-height: 1.5em) and from the explicit
   heading margins below.

   white-space: pre-wrap mirrors Quill's .ql-editor so literal \n and \t chars inside a
   paragraph render as line breaks / tab widths (otherwise multi-line "Client:/Date:/Signature:"
   rows collapse onto a single line in merged/client/portal views). */
:where(:not(#quillEditor)) .ql-editor > p,
:where(:not(#quillEditor)) > p {
  white-space: pre-wrap !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}
:where(:not(#quillEditor)) .ql-editor > h1,
:where(:not(#quillEditor)) .ql-editor > h2,
:where(:not(#quillEditor)) .ql-editor > h3,
:where(:not(#quillEditor)) .ql-editor > h4,
:where(:not(#quillEditor)) > h1,
:where(:not(#quillEditor)) > h2,
:where(:not(#quillEditor)) > h3,
:where(:not(#quillEditor)) > h4 {
  margin: 0.65em 0 0.4em !important;
  line-height: 1.25 !important;
  font-weight: 700 !important;
}
:where(:not(#quillEditor)) .ql-editor > h1:first-child,
:where(:not(#quillEditor)) .ql-editor > h2:first-child,
:where(:not(#quillEditor)) .ql-editor > h3:first-child,
:where(:not(#quillEditor)) .ql-editor > h4:first-child,
:where(:not(#quillEditor)) > h1:first-child,
:where(:not(#quillEditor)) > h2:first-child,
:where(:not(#quillEditor)) > h3:first-child,
:where(:not(#quillEditor)) > h4:first-child {
  margin-top: 0 !important;
}
