/*
 * 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(#quillEditor *)):where(:not(#emailBodyEditor *)):where(:not(#qlEmailBodyEditor *)) .text-block-shell {
  border-radius: 0 !important;
  margin: 0 !important;
  box-shadow: none !important;
  outline: none !important;
}
:where(:not(#quillEditor *)):where(:not(#emailBodyEditor *)):where(:not(#qlEmailBodyEditor *)) .text-block-shell[data-border-style="none"] {
  border: none !important;
}

/* ── Quill editor wrapper: zero-chrome when it leaks into preview ── */
/* Exclude live composers (#quillEditor, #emailBodyEditor, …) and nested .ql-container shells. */
:where(:not(#quillEditor):not(#prefEmailSignatureEditor):not(#qlEmailBodyEditor):not(#emailBodyEditor):not(.ql-container)) > .ql-editor,
:where(:not(#quillEditor):not(#qlEmailBodyEditor):not(#emailBodyEditor)) > .ql-container:not(#prefEmailSignatureEditor):not(#qlEmailBodyEditor):not(#emailBodyEditor) > .ql-editor {
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

/* Live composer editors (nested .ql-container > .ql-editor) — comfortable body inset */
#emailComposerContent #emailBodyEditor .ql-editor,
.email-composer-modal #emailBodyEditor .ql-editor {
  min-height: 280px !important;
  padding: 16px 20px !important;
  line-height: 1.55 !important;
  user-select: text !important;
  -webkit-user-select: text !important;
}

#composerModal.print-layout-mode #quillEditor .ql-editor {
  padding-top: calc(var(--doc-nav-height, 0px) + var(--doc-margin-top, 48px)) !important;
  padding-right: var(--doc-margin-right, 48px) !important;
  padding-bottom: var(--doc-margin-bottom, 48px) !important;
  padding-left: var(--doc-margin-left, 48px) !important;
  line-height: 1.6 !important;
  user-select: text !important;
  -webkit-user-select: text !important;
}

#composerModal.composer-modal--email.print-layout-mode #quillEditor .ql-editor {
  padding-top: calc(var(--doc-nav-height, 0px) + var(--doc-margin-top, 16px)) !important;
  padding-right: var(--doc-margin-right, 20px) !important;
  padding-bottom: var(--doc-margin-bottom, 16px) !important;
  padding-left: var(--doc-margin-left, 20px) !important;
}

#userPreferencesModal #prefEmailSignatureEditor .ql-editor {
  min-height: 72px !important;
  padding: 10px 12px !important;
  font-size: 13px !important;
  user-select: text !important;
  -webkit-user-select: text !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;
}

/* ── Unified invoice sheet (header + accounting line items = one document) ── */
:where(:not(.ql-editor)) .line-items-fill--invoice-header,
:where(:not(.ql-editor)) .line-items-fill--invoice-accounting,
:where(:not(.ql-editor)) .td-book-client-invoice-zone > .line-items-fill,
:where(:not(.ql-editor)) .td-book-client-invoice-zone > .td-invoice-header-fill,
:where(:not(.ql-editor)) .td-book-client-invoice-zone > .portal-special-block {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

:where(:not(.ql-editor)) .line-items-fill--invoice-header .line-items-preview-invoice-header,
:where(:not(.ql-editor)) .line-items-fill--invoice-header .line-items-preview-invoice-header--simple,
:where(:not(.ql-editor)) .td-book-client-invoice-zone .line-items-preview-invoice-header--simple {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

:where(:not(.ql-editor)) .line-items-fill--invoice-accounting > .line-items-fill-label {
  display: none !important;
}

:where(:not(.ql-editor)) .line-items-fill--invoice-accounting .td-invoice-sheet-lines,
:where(:not(.ql-editor)) .td-book-client-invoice-zone .td-invoice-sheet-lines {
  padding: 0 18px 18px !important;
}

/* Client View / portal: adjacent embed pair shares one outer card */
:where(:not(.ql-editor)) > .line-items-embed[data-field-type="invoice_header_block"]:has(+ .line-items-embed[data-field-type="invoice_block"]),
:where(:not(.ql-editor)) .ql-editor > .line-items-embed[data-field-type="invoice_header_block"]:has(+ .line-items-embed[data-field-type="invoice_block"]) {
  margin: 16px 0 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

:where(:not(.ql-editor)) > .line-items-embed[data-field-type="invoice_header_block"] + .line-items-embed[data-field-type="invoice_block"],
:where(:not(.ql-editor)) .ql-editor > .line-items-embed[data-field-type="invoice_header_block"] + .line-items-embed[data-field-type="invoice_block"] {
  margin: 0 0 16px !important;
  padding: 0 !important;
  border: 1px solid #e2e8f0 !important;
  border-top: none !important;
  border-radius: 0 0 16px 16px !important;
  background: #fff !important;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08) !important;
  overflow: hidden !important;
}

/* Fill nodes without embed wrappers (not inside doc-fill zone — zone supplies the shell) */
:where(:not(.ql-editor)) :not(.td-book-client-invoice-zone) > .line-items-fill--invoice-header:has(+ .line-items-fill--invoice-accounting) {
  margin: 16px 0 0 !important;
  border: 1px solid #e2e8f0 !important;
  border-bottom: none !important;
  border-radius: 16px 16px 0 0 !important;
  background: #fff !important;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08) !important;
  overflow: hidden !important;
}

:where(:not(.ql-editor)) :not(.td-book-client-invoice-zone) > .line-items-fill--invoice-header:has(+ .line-items-fill--invoice-accounting) + .line-items-fill--invoice-accounting {
  margin: 0 0 16px !important;
  border: 1px solid #e2e8f0 !important;
  border-top: none !important;
  border-radius: 0 0 16px 16px !important;
  background: #fff !important;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08) !important;
  overflow: hidden !important;
}
