/* Set the height of the editor */
.ck-editor__editable_inline {
  min-height: 250px;
  position: relative;
}

/*
 * Keep long content scrolling inside the editor, as CKEditor 4 did, so the
 * toolbar stays on screen. Without a cap the editor grows to fit the whole
 * email and the toolbar scrolls off the page.
 */
.ck.ck-editor__main > .ck-editor__editable {
  max-height: 70vh;
  overflow-y: auto;
}

/*
 * Source view sizes its box to the full text, and the textarea fills the box.
 * Cap the box and let the textarea scroll its own text. The minimum height
 * goes on the box too: a minimum on the textarea alone overflows the box,
 * which cuts off the last lines when the window is short.
 */
.ck.ck-editor__main > .ck-source-editing-area {
  min-height: min(400px, 70vh);
  max-height: 70vh;
}

.ck.ck-editor__main > .ck-source-editing-area textarea {
  min-height: 0;
  overflow-y: auto;
}

/* Set the width of the editor */
.ck.ck-editor {
  max-width: 95%;
}

/* Place elfinder above CiviCRM popup */
.ui-front.dialogelfinder {
  z-index: 9000;
}

/*
 * Keep CKEditor's balloons, such as the link box, above CiviCRM popups.
 * CKEditor puts them at z-index 1000, and some themes put popups higher:
 * Shoreditch sets .crm-container.ui-dialog to 2001, which hid the link box.
 * Only the balloons are raised (they sit in .ck-body-wrapper), not the
 * editor's toolbar, so a popup still covers an editor behind it. They stay
 * below elFinder (9000) and CKEditor's own dialogs (9999).
 */
.ck-body-wrapper {
  --ck-z-panel: calc(var(--ck-z-default) + 2999);
}

/*
 * Show tables where the saved HTML puts them. CKEditor centres every table
 * in the editor, but a table saved without an alignment has no centring, so
 * emails and PDFs show it at the left, as CKEditor 4 did. A table with an
 * align attribute keeps that alignment, and one floated left or right from
 * the table properties keeps its float, which is an inline style.
 */
html body .ck-content .table {
  margin-left: 0;
  margin-right: 0;
}

html body .ck-content .table:has(> table[align="center"]),
html body .ck-content .table:has(> table.civi-email-align-center) {
  margin-left: auto;
  margin-right: auto;
}

html body .ck-content .table:has(> table[align="right"]),
html body .ck-content .table:has(> table.civi-email-align-right) {
  margin-left: auto;
  margin-right: 0;
}

/*
 * Let a table that is 100% wide, such as an email's background table, fill
 * the editor as it fills the email. CKEditor draws a table at the width of
 * the box around it, and that box shrinks to the table's content.
 */
html body .ck-content .table:has(> table[width="100%"]) {
  width: 100%;
}

/* Legacy email table alignment must remain visible in both normal and
 * fullscreen editing without inheriting CiviCRM's generic table styles. */
html body .ck-content table.civi-email-align-center {
  margin-left: auto !important;
  margin-right: auto !important;
}

html body .ck-content table.civi-email-align-left {
  margin-left: 0 !important;
  margin-right: auto !important;
}

html body .ck-content table.civi-email-align-right {
  margin-left: auto !important;
  margin-right: 0 !important;
}

.image.image-style-align-center {
  margin: 0 auto;
}

.image.image-style-align-left {
  float: left;
  margin-right: 1em;
}

.image.image-style-align-right,
.image.image-style-side {
  float: right;
  margin-left: 1em;
}

/* CKEditor does not support dark theme, so override the dark theme's white text on CKEditor's white background. */
html body .ck.ck-editor__main * {
  color: black;
}

.ck-content .crm-lead {
  font-size: 1.15em;
  line-height: 1.5;
  color: #33495e;
}

.ck-content .crm-small {
  font-size: 0.85em;
  color: #6b7785;
}

.ck-content .crm-callout {
  padding: 0.75em 1em;
  border-left: 4px solid #4d7fa4;
  background: #f2f7fa;
}

.ck-content .crm-table-bordered,
.ck-content .crm-table-bordered td,
.ck-content .crm-table-bordered th {
  border: 1px solid #b5c2cd;
}

.ck-content .crm-marker {
  background: #fdf3a7;
}

.ck-content .crm-muted {
  color: #6b7785;
}

.ck-source-editing-area textarea {
  min-height: 400px;
  font-family: monospace;
}

/* Keep oversized images inside the editor box. */
.ck-content img {
  max-width: 100%;
  height: auto;
}

.elfinder .elfinder-overlay,
.elfinder-overlay {
  z-index: 999 !important;
}
