/*
 * Lexxy Editor Custom Content Styles
 *
 * These styles ensure the Lexxy editor content area matches
 * the rendered document view styling.
 *
 * Using !important to override Lexxy's default styles.
 * Using higher specificity to ensure these styles win.
 */

/* Hide the rendered content div when editor is active */
lexxy-editor:not(.lexxy-editor--empty) div.lexxy-content {
  display: none !important;
}

/* Target BOTH the editor content AND the rendered content */
lexxy-editor div[contenteditable="true"].lexxy-editor__content,
lexxy-editor div.lexxy-content,
.lexxy-content {
  /* The app's face (Inter, shipped with the app), so editing looks like the rendered document. */
  font-family: "Inter", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', sans-serif !important;
  font-size: 16px !important;
  line-height: 1.5 !important;
  color: #333 !important;
  padding: 24px !important;
  cursor: text !important;
  user-select: text !important;
}

/* Ensure the editable area is interactive */
lexxy-editor div[contenteditable="true"].lexxy-editor__content {
  pointer-events: auto !important;
  position: relative !important;
  z-index: 1 !important;
}

/* Headings - light blue color matching view mode */
lexxy-editor div.lexxy-editor__content h1,
lexxy-editor div.lexxy-content h1,
.lexxy-content h1,
lexxy-editor div.lexxy-editor__content h2,
lexxy-editor div.lexxy-content h2,
.lexxy-content h2,
lexxy-editor div.lexxy-editor__content h3,
lexxy-editor div.lexxy-content h3,
.lexxy-content h3,
lexxy-editor div.lexxy-editor__content h4,
lexxy-editor div.lexxy-content h4,
.lexxy-content h4,
lexxy-editor div.lexxy-editor__content h5,
lexxy-editor div.lexxy-content h5,
.lexxy-content h5,
lexxy-editor div.lexxy-editor__content h6,
lexxy-editor div.lexxy-content h6,
.lexxy-content h6 {
  color: #3baaf0 !important;
  font-weight: 400 !important;
  margin-bottom: 0.5em !important;
  line-height: 1.2 !important;
}

lexxy-editor div.lexxy-editor__content h1,
lexxy-editor div.lexxy-content h1,
.lexxy-content h1 {
  font-size: 26px !important;
  margin-top: 2.2em !important;
}

lexxy-editor div.lexxy-editor__content h1:first-of-type,
lexxy-editor div.lexxy-content h1:first-of-type,
.lexxy-content h1:first-of-type,
lexxy-editor div.lexxy-editor__content h2:first-of-type,
lexxy-editor div.lexxy-content h2:first-of-type,
.lexxy-content h2:first-of-type,
lexxy-editor div.lexxy-editor__content h3:first-of-type,
lexxy-editor div.lexxy-content h3:first-of-type,
.lexxy-content h3:first-of-type {
  margin-top: 0.4em !important;
}

lexxy-editor div.lexxy-editor__content h2,
lexxy-editor div.lexxy-content h2,
.lexxy-content h2 {
  font-size: 22px !important;
  margin-top: 2em !important;
  padding-left: 0 !important;
}

lexxy-editor div.lexxy-editor__content h3,
lexxy-editor div.lexxy-content h3,
.lexxy-content h3 {
  font-size: 20px !important;
  margin-top: 1.5em !important;
  padding-left: 0 !important;
}

lexxy-editor div.lexxy-editor__content h4,
lexxy-editor div.lexxy-content h4,
.lexxy-content h4 {
  font-size: 18px !important;
  margin-top: 1.5em !important;
}

/* Paragraphs */
lexxy-editor div.lexxy-editor__content p,
lexxy-editor div.lexxy-content p,
.lexxy-content p {
  margin: 0 0 0.25em 0 !important;
  line-height: 1.5 !important;
}

/* Lists */
lexxy-editor div.lexxy-editor__content ul,
lexxy-editor div.lexxy-content ul,
.lexxy-content ul {
  margin: 0 0 1em 0 !important;
  padding-left: 1.5em !important;
  list-style-type: disc !important;
}

lexxy-editor div.lexxy-editor__content ol,
lexxy-editor div.lexxy-content ol,
.lexxy-content ol {
  margin: 0 0 1em 0 !important;
  padding-left: 1.5em !important;
}

lexxy-editor div.lexxy-editor__content li,
lexxy-editor div.lexxy-content li,
.lexxy-content li {
  margin-bottom: 0.5em !important;
  line-height: 1.5 !important;
}

/* Links - matching editor blue */
lexxy-editor div.lexxy-editor__content a,
lexxy-editor div.lexxy-content a,
.lexxy-content a {
  color: #2577c9 !important;
  text-decoration: none !important;
}

lexxy-editor div.lexxy-editor__content a:hover,
lexxy-editor div.lexxy-content a:hover,
.lexxy-content a:hover {
  text-decoration: underline !important;
}

lexxy-editor div.lexxy-editor__content img,
lexxy-editor div.lexxy-content img,
.lexxy-content img {
  display: block !important;
  max-width: min(300px, 100%) !important;
  width: auto !important;
  height: auto !important;
  margin: 0.75rem 0 !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 10px !important;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08) !important;
}

/* Blockquotes - but NOT tip-box-blockquotes */
lexxy-editor div.lexxy-editor__content blockquote:not(.tip-box-blockquote),
lexxy-editor div.lexxy-content blockquote:not(.tip-box-blockquote),
.lexxy-content blockquote:not(.tip-box-blockquote) {
  border-left: 4px solid #3baaf0 !important;
  padding-left: 1em !important;
  margin: 1em 0 !important;
  color: #666 !important;
}

/* Code */
lexxy-editor div.lexxy-editor__content code,
lexxy-editor div.lexxy-content code,
.lexxy-content code {
  background-color: #f3f4f6 !important;
  padding: 0.2em 0.4em !important;
  border-radius: 3px !important;
  font-family: 'Courier New', Courier, monospace !important;
  font-size: 0.9em !important;
}

lexxy-editor div.lexxy-editor__content pre,
lexxy-editor div.lexxy-content pre,
.lexxy-content pre {
  background-color: #f3f4f6 !important;
  padding: 1em !important;
  border-radius: 5px !important;
  overflow-x: auto !important;
  margin: 1.5em 0 !important;
}

lexxy-editor div.lexxy-editor__content pre code,
lexxy-editor div.lexxy-content pre code,
.lexxy-content pre code {
  background: none !important;
  padding: 0 !important;
}

/* Tables */
lexxy-editor div.lexxy-editor__content table,
lexxy-editor div.lexxy-content table,
.lexxy-content table {
  border-collapse: collapse !important;
  width: 100% !important;
  margin: 1.5em 0 !important;
}

/* Wide tables scroll inside their own wrapper, so every column stays
   reachable. Lexxy wraps tables in figure.lexxy-content__table-wrapper and
   the document view wraps stored bare tables the same way (DocumentsHelper).
   The wrapper must stay a plain block: daisyUI's `.card figure` turns it into
   a centered flex box, which pushes the left part of a wide table out of
   scroll reach. */
lexxy-editor div.lexxy-editor__content .lexxy-content__table-wrapper,
lexxy-editor div.lexxy-content .lexxy-content__table-wrapper,
.lexxy-content .lexxy-content__table-wrapper {
  display: block !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  margin: 1.5em 0 !important;
}

lexxy-editor div.lexxy-editor__content .lexxy-content__table-wrapper > table,
lexxy-editor div.lexxy-content .lexxy-content__table-wrapper > table,
.lexxy-content .lexxy-content__table-wrapper > table {
  margin: 0 !important;
}

lexxy-editor div.lexxy-editor__content table td,
lexxy-editor div.lexxy-content table td,
.lexxy-content table td,
lexxy-editor div.lexxy-editor__content table th,
lexxy-editor div.lexxy-content table th,
.lexxy-content table th {
  border: none !important;
  padding: 10px 15px !important;
  vertical-align: top !important;
  border-bottom: 1px solid #eaeaea !important;
}

/* Horizontal rule - gradient */
lexxy-editor div.lexxy-editor__content hr,
lexxy-editor div.lexxy-content hr,
.lexxy-content hr {
  border: none !important;
  height: 3px !important;
  background: linear-gradient(to right, #39c0ff, #2577c9) !important;
  margin: 2em 0 !important;
}

/* Strong and emphasis */
lexxy-editor div.lexxy-editor__content .lexxy-content__bold,
lexxy-editor div.lexxy-content .lexxy-content__bold,
.lexxy-content .lexxy-content__bold,
lexxy-editor div.lexxy-editor__content strong,
lexxy-editor div.lexxy-content strong,
.lexxy-content strong {
  font-weight: 600 !important;
}

lexxy-editor div.lexxy-editor__content .lexxy-content__italic,
lexxy-editor div.lexxy-content .lexxy-content__italic,
.lexxy-content .lexxy-content__italic,
lexxy-editor div.lexxy-editor__content em,
lexxy-editor div.lexxy-content em,
.lexxy-content em {
  font-style: italic !important;
}

lexxy-editor div.lexxy-editor__content .lexxy-content__underline,
lexxy-editor div.lexxy-content .lexxy-content__underline,
.lexxy-content .lexxy-content__underline,
lexxy-editor div.lexxy-editor__content u,
lexxy-editor div.lexxy-content u,
.lexxy-content u {
  text-decoration-line: underline !important;
}

lexxy-editor div.lexxy-editor__content .lexxy-content__strikethrough,
lexxy-editor div.lexxy-content .lexxy-content__strikethrough,
.lexxy-content .lexxy-content__strikethrough,
lexxy-editor div.lexxy-editor__content s,
lexxy-editor div.lexxy-content s,
.lexxy-content s,
lexxy-editor div.lexxy-editor__content strike,
lexxy-editor div.lexxy-content strike,
.lexxy-content strike,
lexxy-editor div.lexxy-editor__content del,
lexxy-editor div.lexxy-content del,
.lexxy-content del {
  text-decoration-line: line-through !important;
}

lexxy-editor div.lexxy-editor__content .lexxy-content__strikethrough.lexxy-content__underline,
lexxy-editor div.lexxy-content .lexxy-content__strikethrough.lexxy-content__underline,
.lexxy-content .lexxy-content__strikethrough.lexxy-content__underline,
lexxy-editor div.lexxy-editor__content u s,
lexxy-editor div.lexxy-content u s,
.lexxy-content u s,
lexxy-editor div.lexxy-editor__content s u,
lexxy-editor div.lexxy-content s u,
.lexxy-content s u {
  text-decoration-line: underline line-through !important;
}

/* Tip box with info icon */
/* Very specific selectors to override lexxy defaults */
lexxy-editor div[contenteditable="true"].lexxy-editor__content blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-editor__content blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-content blockquote.tip-box-blockquote,
.lexxy-content blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-editor__content .tip-box,
lexxy-editor div.lexxy-content .tip-box,
.lexxy-content .tip-box {
  display: block !important;
  background-color: #ffffff !important;
  border-radius: 4px !important;
  padding: 24px 20px 20px 60px !important; /* Extra top padding for gradient */
  margin: 1.5em 0 !important;
  position: relative !important;
  /* Remove all default borders */
  border: none !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: none !important;
  border-top: none !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  clear: both !important;
  font-style: normal !important; /* Override blockquote italic */
  color: #333 !important; /* Override blockquote color */
}

/* Gradient top border using ::after pseudo-element for crisp rendering */
lexxy-editor div[contenteditable="true"].lexxy-editor__content blockquote.tip-box-blockquote::after,
lexxy-editor div.lexxy-editor__content blockquote.tip-box-blockquote::after,
lexxy-editor div.lexxy-content blockquote.tip-box-blockquote::after,
.lexxy-content blockquote.tip-box-blockquote::after,
lexxy-editor div.lexxy-editor__content .tip-box::after,
lexxy-editor div.lexxy-content .tip-box::after,
.lexxy-content .tip-box::after {
  content: "" !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 4px !important;
  background: linear-gradient(to right, #39c0ff, #2577c9) !important;
  border-radius: 4px 4px 0 0 !important;
  z-index: 1 !important;
}

/* Info icon styling - positioned absolutely */
lexxy-editor div.lexxy-editor__content .tip-box::before,
lexxy-editor div.lexxy-content .tip-box::before,
.lexxy-content .tip-box::before,
lexxy-editor div.lexxy-editor__content blockquote.tip-box-blockquote::before,
lexxy-editor div.lexxy-content blockquote.tip-box-blockquote::before,
.lexxy-content blockquote.tip-box-blockquote::before {
  content: "i" !important;
  display: block !important;
  position: absolute !important;
  left: 20px !important;
  top: 24px !important; /* Adjusted for new padding */
  width: 24px !important;
  height: 24px !important;
  color: #39c0ff !important;
  text-align: center !important;
  line-height: 24px !important;
  border: 2px solid #39c0ff !important;
  border-radius: 50% !important;
  font-size: 16px !important;
  font-weight: bold !important;
  font-style: italic !important;
  z-index: 2 !important; /* Above gradient */
}

/* Tip box paragraphs */
lexxy-editor div.lexxy-editor__content .tip-box p,
lexxy-editor div.lexxy-content .tip-box p,
.lexxy-content .tip-box p,
lexxy-editor div.lexxy-editor__content blockquote.tip-box-blockquote p,
lexxy-editor div.lexxy-content blockquote.tip-box-blockquote p,
.lexxy-content blockquote.tip-box-blockquote p {
  display: block !important;
  width: 100% !important;
  margin-bottom: 0.5em !important;
  min-height: 1.2em !important;
}

lexxy-editor div.lexxy-editor__content .tip-box p:last-child,
lexxy-editor div.lexxy-content .tip-box p:last-child,
.lexxy-content .tip-box p:last-child,
lexxy-editor div.lexxy-editor__content blockquote.tip-box-blockquote p:last-child,
lexxy-editor div.lexxy-content blockquote.tip-box-blockquote p:last-child,
.lexxy-content blockquote.tip-box-blockquote p:last-child {
  margin-bottom: 0 !important;
}

/* Explicit rules for tip boxes directly after headings */
lexxy-editor div.lexxy-editor__content h1 + .tip-box,
lexxy-editor div.lexxy-content h1 + .tip-box,
.lexxy-content h1 + .tip-box,
lexxy-editor div.lexxy-editor__content h2 + .tip-box,
lexxy-editor div.lexxy-content h2 + .tip-box,
.lexxy-content h2 + .tip-box,
lexxy-editor div.lexxy-editor__content h3 + .tip-box,
lexxy-editor div.lexxy-content h3 + .tip-box,
.lexxy-content h3 + .tip-box,
lexxy-editor div.lexxy-editor__content h4 + .tip-box,
lexxy-editor div.lexxy-content h4 + .tip-box,
.lexxy-content h4 + .tip-box,
lexxy-editor div.lexxy-editor__content h1 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-content h1 + blockquote.tip-box-blockquote,
.lexxy-content h1 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-editor__content h2 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-content h2 + blockquote.tip-box-blockquote,
.lexxy-content h2 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-editor__content h3 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-content h3 + blockquote.tip-box-blockquote,
.lexxy-content h3 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-editor__content h4 + blockquote.tip-box-blockquote,
lexxy-editor div.lexxy-content h4 + blockquote.tip-box-blockquote,
.lexxy-content h4 + blockquote.tip-box-blockquote {
  clear: both !important;
  padding-left: 60px !important; /* Force correct padding */
  text-indent: 0 !important; /* Reset any inherited indentation */
  margin-top: 1em !important; /* Add some space after heading */
}

/* A document's blocks on the tracked-changes sheet of an AuditMagic proposal:
   the document's own styles, a step smaller for the chat card. Each block is
   its own element, so outer margins are dropped. */
div.chat-document-diff.lexxy-content {
  padding: 0 1.25rem !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  cursor: auto !important;
}

/* On a phone the approval card is the only box around the diff. */
@media (max-width: 39.999rem) {
  div.chat-document-diff.lexxy-content {
    padding: 0 !important;
  }
}

div.chat-document-diff.lexxy-content h1,
div.chat-document-diff.lexxy-content h2,
div.chat-document-diff.lexxy-content h3,
div.chat-document-diff.lexxy-content h4,
div.chat-document-diff.lexxy-content h5,
div.chat-document-diff.lexxy-content h6 {
  margin: 0.6em 0 0.2em !important;
}

div.chat-document-diff.lexxy-content h1 { font-size: 20px !important; }
div.chat-document-diff.lexxy-content h2 { font-size: 18px !important; }
div.chat-document-diff.lexxy-content h3 { font-size: 16px !important; }
div.chat-document-diff.lexxy-content h4 { font-size: 15px !important; }

div.chat-document-diff.lexxy-content p,
div.chat-document-diff.lexxy-content ul,
div.chat-document-diff.lexxy-content ol,
div.chat-document-diff.lexxy-content li,
div.chat-document-diff.lexxy-content blockquote:not(.tip-box-blockquote) {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

div.chat-document-diff.lexxy-content table {
  margin: 0 !important;
  max-width: 100% !important;
  table-layout: fixed !important;
}

div.chat-document-diff.lexxy-content table td {
  padding: 4px 8px !important;
  overflow-wrap: anywhere !important;
}

/* On a phone words stay whole. Each table row is a table of its own, so the rows of a sheet share one column grid
   (subgrid): a column is as wide as its longest word, up to 14rem, and the sheet scrolls sideways where that is
   wider than the phone. Text between the rows keeps the width of the sheet. */
@media (max-width: 39.999rem) {
  [data-chat-block-diff] {
    container-type: inline-size;
  }

  [data-chat-block-diff] div.grid:has(> .chat-document-diff > table) {
    grid-template-columns: repeat(24, minmax(min-content, auto));
    column-gap: 0;
    justify-content: start;
    width: max-content;
    min-width: 100%;
    max-width: 100%;
  }

  [data-chat-block-diff] div.grid > * {
    grid-column: 1 / -1;
    width: 100cqi;
    contain: inline-size;
  }

  [data-chat-block-diff] div.grid > div.chat-document-diff:has(> table td:nth-child(2)) {
    display: grid;
    grid-template-columns: subgrid;
    width: auto;
    contain: none;
  }

  div.chat-document-diff.lexxy-content > table:has(td:nth-child(2)),
  div.chat-document-diff.lexxy-content > table:has(td:nth-child(2)) > tbody,
  div.chat-document-diff.lexxy-content > table:has(td:nth-child(2)) > tbody > tr {
    display: grid !important;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    width: auto !important;
    max-width: none !important;
  }

  div.chat-document-diff.lexxy-content > table td:not(:only-child) {
    max-width: 14rem !important;
  }

  div.chat-document-diff.lexxy-content > table td:nth-child(n):not(:only-child) {
    min-width: 4rem !important;
    width: auto !important;
  }

  /* A shadow at the right edge while columns follow there; the local layer covers it at the end. */
  [data-chat-block-diff] > div {
    background:
      linear-gradient(to left, var(--color-base-100) 30%, transparent) right / 2rem 100% no-repeat local,
      linear-gradient(to left, rgb(0 0 0 / 0.08), transparent) right / 0.75rem 100% no-repeat scroll,
      var(--color-base-100);
  }

  div.chat-document-diff.lexxy-content table td {
    overflow-wrap: break-word !important;
    word-break: normal !important;
  }
}
