/* Lightweight lexxy-content styles for public pages.
   Covers rich text output without loading the full lexxy editor bundle. */

:where(.lexxy-content) {
  color: inherit;
  line-height: 1.6;

  h1, h2, h3, h4, h5, h6 {
    display: block;
    font-weight: bold;
    margin-block: 0 1rem;
    overflow-wrap: break-word;
    text-wrap: balance;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  h4 { font-size: 1rem; }
  h5 { font-size: 0.875rem; }
  h6 { font-size: 0.75rem; }

  p, ul, ol, dl, blockquote, figure {
    margin-block: 0 1rem;
    overflow-wrap: break-word;
  }

  /* Preserve runs of spaces authors type for spacing/placement (the editor's
     contenteditable already uses pre-wrap). Scoped to text blocks so the
     indentation ActionText's content partial adds *between* elements stays
     collapsed. `pre`/`code` keep their own white-space rules below. */
  :where(p, li, td, th, dd, dt, h1, h2, h3, h4, h5, h6, blockquote) {
    white-space: pre-wrap;
  }

  a {
    color: oklch(57% 0.19 260);
    text-decoration: underline;
  }

  blockquote {
    border-inline-start: 0.25em solid #d4d4d8;
    font-style: italic;
    margin: 1rem 0;
    padding: 0.5lh 2ch;

    p:last-child {
      margin-block-end: 0;
    }
  }

  p:empty {
    display: none;
  }

  /* Merge fill-field: a value rendered on top of a fixed-width underline,
     produced by ContractMergeService for {{var|line}} placeholders. Put any
     caption (e.g. "(инициалы, фамилия)") on the next line in the template. */
  .field-line {
    display: inline-block;
    min-width: 6cm;
    text-align: center;
    border-bottom: 1px solid currentColor;
    line-height: 1.15;
  }

  img, video {
    inline-size: auto;
    margin-inline: auto;
    max-inline-size: 100%;
    height: auto;
  }

  code, pre {
    background-color: #f5f5f4;
    border-radius: 0.5ch;
    font-family: ui-monospace, "Menlo", "Monaco", Consolas, monospace;
    font-size: 0.9em;
    padding: 0.25ch 0.5ch;
  }

  pre, code[data-language] {
    display: block;
    margin-block: 0 1rem;
    overflow-x: auto;
    padding: 1ch;
    tab-size: 2;
    white-space: pre;
  }

  ul, ol {
    padding-inline-start: 1.5em;
  }

  li {
    list-style-type: disc;
  }

  li.lexxy-nested-listitem {
    list-style-type: none;

    ol, ul {
      margin: 0;
    }
  }

  > :last-child {
    margin-block-end: 0;
  }

  /* Tables */
  :where(.lexxy-content__table-wrapper) {
    margin: 0;
    margin-block: 1ch;
    overflow-x: auto;
  }

  table {
    border-collapse: collapse;
    border-spacing: 0;
    inline-size: 100%;

    /* Honour per-column widths set via the editor's resize handles. Size the
       table to the sum of those widths instead of stretching to 100%, so the
       collapsed outer-right border isn't clipped by the wrapper's overflow box
       (a full-width border-collapse table butts its border against the edge). */
    &:has(> colgroup > col[style*="width"]) {
      table-layout: fixed;
      inline-size: auto;
      max-inline-size: 100%;
    }

    th, td {
      border: 1px solid #d4d4d8;
      padding: 1ch;
      text-align: start;

      *:last-child {
        margin-block-end: 0;
      }
    }

    th, td.lexxy-content__table-cell--header {
      background-color: #f5f5f4;
      font-weight: bold;
    }
  }
}

/* Generated leasing payment schedule ({{payment_schedule}}). Compact 9-column
   table sized to fit A4 portrait; class-level rules override the base
   :where(.lexxy-content) table styling (which is zero-specificity). */
.payment-schedule {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 7pt;
  line-height: 1.2;
  margin-block: 0.5rem;
}

.payment-schedule th,
.payment-schedule td {
  border: 1px solid #999;
  padding: 2px 3px;
  vertical-align: top;
  text-align: left;
  white-space: normal;
  overflow-wrap: break-word;
  font-weight: normal;
  background: none;
}

.payment-schedule th {
  font-weight: bold;
  text-align: center;
}

.payment-schedule td.num,
.payment-schedule th.num {
  text-align: right;
  white-space: nowrap;
}

.payment-schedule th.num {
  text-align: center;
}

/* Attachments */
:where(.attachment) {
  display: block;
  inline-size: fit-content;
  max-inline-size: 100%;
  margin-inline: auto;
  text-align: center;
}

:where(.attachment--preview) {
  border-radius: 0.5ch;

  img, video {
    display: block;
    margin-inline: auto;
    max-inline-size: 100%;
    height: auto;
  }
}

:where(.attachment__caption) {
  color: #78716c;
  font-size: 0.875rem;
  margin-block-start: 1ch;
}

:where(.attachment--file) {
  align-items: center;
  display: flex;
  gap: 1ch;
  inline-size: auto;
}

/* Horizontal divider */
:where(.horizontal-divider) {
  margin: 0;
  margin-block-end: 0.5em;
  padding: 1.5em 0 0.5em;

  hr {
    border: 0;
    border-block-end: 1px solid currentColor;
    inline-size: 20%;
    margin: 0;
  }
}
