.fe-richtext {
  --fe-richtext-height: 400px;
  width: 100%;
  overflow-anchor: none;
}

.fe-richtext-preview {
  height: var(--fe-richtext-height);
  overflow-y: auto;
  cursor: text;
  line-height: 1.5;
  overflow-wrap: break-word;
  color: var(--blue-5);
}

fieldset:disabled .fe-richtext-preview {
  background-color: var(--bs-secondary-bg, #e9ecef);
  opacity: 1;
  cursor: default;
  color: var(--bs-secondary-color, #6c757d);
}

.fe-richtext-preview:empty::before {
  content: attr(data-placeholder);
  color: var(--bs-secondary-color, #6c757d);
  display: block;
}

.fe-richtext-placeholder {
  color: var(--bs-secondary-color, #6c757d);
}

.fe-richtext-placeholder p,
.fe-richtext-placeholder ul,
.fe-richtext-placeholder ol {
  margin: 0 0 0.5em;
}

.fe-richtext-placeholder ul,
.fe-richtext-placeholder ol {
  padding-left: 1.5em;
}

.fe-richtext-preview p,
.fe-richtext-preview ol,
.fe-richtext-preview ul {
  margin: 0;
}

.fe-richtext-preview ol,
.fe-richtext-preview ul {
  padding-left: 1.5em;
}

.fe-richtext-preview,
.fe-richtext-editor-wrap .ql-editor,
.fe-richtext-popup-view,
.fe-richtext-quill-placeholder {
  scrollbar-width: thin;
  scrollbar-color: #b6bec9 transparent;
}

.fe-richtext-preview::-webkit-scrollbar,
.fe-richtext-editor-wrap .ql-editor::-webkit-scrollbar,
.fe-richtext-popup-view::-webkit-scrollbar,
.fe-richtext-quill-placeholder::-webkit-scrollbar {
  width: 10px;
}

.fe-richtext-preview::-webkit-scrollbar-thumb,
.fe-richtext-editor-wrap .ql-editor::-webkit-scrollbar-thumb,
.fe-richtext-popup-view::-webkit-scrollbar-thumb,
.fe-richtext-quill-placeholder::-webkit-scrollbar-thumb {
  background-color: #b6bec9;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.fe-richtext-preview::-webkit-scrollbar-track,
.fe-richtext-editor-wrap .ql-editor::-webkit-scrollbar-track,
.fe-richtext-popup-view::-webkit-scrollbar-track,
.fe-richtext-quill-placeholder::-webkit-scrollbar-track {
  background: transparent;
}

.fe-richtext-preview strong,
.fe-richtext-preview b,
.fe-richtext-editor-wrap .ql-editor strong,
.fe-richtext-editor-wrap .ql-editor b,
.fe-richtext-popup-view strong,
.fe-richtext-popup-view b {
  font-weight: 800;
}

.fe-richtext-preview img,
.fe-richtext-editor-wrap .ql-editor img,
.fe-richtext-popup-view img {
  max-width: min(100%, 360px);
  max-height: 220px;
  width: auto;
  height: auto;
}

.fe-richtext-editor-wrap .ql-editor img.fe-richtext-image-uploading {
  opacity: 0.45;
}

.fe-richtext-editor-wrap {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  height: var(--fe-richtext-height);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: var(--bs-border-radius, 0.375rem);
  background-color: var(--bs-body-bg, #fff);
}

.fe-richtext-editor-wrap.is-focused {
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.fe-richtext-editor-wrap .ql-container.ql-snow {
  grid-row: 2;
  grid-column: 1;
  min-height: 0;
  overflow: hidden;
  border: none;
  font-family: inherit;
  font-size: inherit;
  position: relative;
}

.fe-richtext-editor-wrap .ql-editor {
  height: 100%;
  overflow-y: auto;
  padding: 0.375rem 0.75rem;
  line-height: 1.5;
  color: var(--blue-5);
}

.fe-richtext-editor-wrap .ql-editor.ql-blank::before {
  display: none;
}

.fe-richtext-editor-wrap .fe-richtext-quill-placeholder {
  grid-row: 2;
  grid-column: 1;
  padding: 0.375rem 0.75rem;
  overflow-y: auto;
  color: var(--bs-secondary-color, #6c757d);
  line-height: 1.5;
  min-height: 0;
  cursor: text;
  z-index: 1;
}

.fe-richtext-quill-placeholder.fe-hidden {
  display: none;
}

.fe-richtext-quill-placeholder p,
.fe-richtext-quill-placeholder ul,
.fe-richtext-quill-placeholder ol {
  margin: 0 0 0.5em;
}

.fe-richtext-quill-placeholder ul,
.fe-richtext-quill-placeholder ol {
  padding-left: 1.5em;
}

.fe-richtext-editor-wrap .ql-tooltip {
  display: none !important;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow {
  grid-row: 1;
  grid-column: 1;
  display: block;
  overflow: hidden;
  max-height: 0;
  visibility: hidden;
  padding: 0 6px;
  border: none;
  border-bottom: 0 solid var(--bs-border-color, #dee2e6);
  transition:
    max-height 0.18s ease,
    padding 0.18s ease,
    border-bottom-width 0.18s ease,
    visibility 0.18s;
}

.fe-richtext-editor-wrap.is-focused .ql-toolbar.ql-snow {
  max-height: 120px;
  visibility: visible;
  padding: 6px 8px;
  border-bottom-width: 1px;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow .ql-formats {
  margin-right: 0;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #444444;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow button svg {
  float: none;
  width: 24px;
  height: 24px;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow button:hover,
.fe-richtext-editor-wrap .ql-toolbar.ql-snow button:focus-visible,
.fe-richtext-editor-wrap .ql-toolbar.ql-snow button.ql-active {
  color: var(--bs-primary, #0d6efd);
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow button[disabled] {
  opacity: 0.35;
  cursor: default;
}

.fe-richtext-editor-wrap .ql-toolbar.ql-snow .ql-formats + .ql-formats {
  border-left: 1px solid var(--bs-border-color, #dee2e6);
  margin-left: 8px;
  padding-left: 8px;
  align-self: center;
  height: 20px;
  display: inline-flex;
  align-items: center;
}

.fe-richtext-link-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1070;
  overscroll-behavior: contain;
}

.fe-richtext-link-popup {
  position: fixed;
  z-index: 1071;
  transform: translateY(-100%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 320px;
  padding: 0.75rem;
  background-color: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: var(--bs-border-radius, 0.375rem);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  outline: none;
}

.fe-richtext-link-popup .fe-control.form-control {
  border-radius: 8px;
}

.fe-richtext-link-popup .fe-control.form-control:focus {
  border-color: var(--blue-2);
  box-shadow: 0 0 0 0.2rem rgb(16 117 253 / 18%);
  outline: none;
}

.fe-richtext-link-popup::before,
.fe-richtext-link-popup::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--fe-link-arrow-x, 50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  transform: translateX(-50%);
}

.fe-richtext-link-popup::before {
  border-top: 9px solid var(--bs-border-color, #dee2e6);
}

.fe-richtext-link-popup::after {
  border-top: 8px solid var(--bs-body-bg, #fff);
  margin-top: -1px;
}

.fe-richtext-link-popup-summary {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.fe-richtext-link-popup-label {
  font-weight: 600;
  color: var(--blue-5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fe-richtext-link-popup-url {
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fe-richtext-link-popup-error {
  font-size: 0.8125rem;
  color: var(--bs-danger, #dc3545);
}

.fe-richtext-link-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.fe-field-control-wrap.has-error .fe-richtext-preview,
.fe-field-control-wrap.has-error .fe-richtext-editor-wrap {
  border-color: var(--bs-danger, #dc3545);
}

.fe-richtext-image-error {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--bs-danger, #dc3545);
}

.fe-table-cell .fe-richtext-preview {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  height: auto;
  min-height: 1.5em;
  max-height: 3em;
  overflow: hidden;
  cursor: pointer;
  border: none;
  border-radius: 0;
  background-color: transparent;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.fe-table-cell .fe-richtext-preview img {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  max-width: 1.25em;
  max-height: 1.25em;
  object-fit: cover;
  border-radius: 4px;
  vertical-align: text-bottom;
  margin: 0 2px;
}

.fe-table-cell:has(.fe-richtext-preview:focus) {
  box-shadow: inset 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

fieldset:disabled .fe-table-cell:has(.fe-richtext-preview:focus) {
  box-shadow: none;
}

fieldset:disabled .fe-table-cell .fe-richtext-preview {
  background-color: transparent;
  cursor: default;
  pointer-events: none;
}

.fe-table-cell:has(.fe-richtext) {
  cursor: pointer;
}

.fe-richtext-cell-popup {
  overflow-anchor: none;
  position: fixed;
  top: anchor(top);
  left: anchor(left);
  width: anchor-size(width);
  max-height: 450px;
  z-index: 99;
  background-color: var(--bs-body-bg, #fff);
  border: 1px solid #86b7fe;
  border-radius: var(--bs-border-radius, 0.375rem);
  box-shadow:
    0 0 0 0.25rem rgba(13, 110, 253, 0.25),
    0 8px 28px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.fe-richtext-cell-popup .fe-richtext-editor-wrap {
  height: auto;
  min-height: 0;
  flex: 1 1 auto;
  border: none;
  border-radius: 0;
}

.fe-richtext-cell-popup .fe-richtext-editor-wrap .ql-editor {
  height: auto;
  min-height: 100px;
  max-height: 360px;
}

.fe-richtext-cell-popup .fe-richtext-editor-wrap.is-focused {
  border-color: transparent;
  box-shadow: none;
}

.fe-richtext-cell-popup .ql-toolbar.ql-snow .ql-formats + .ql-formats {
  border-left: none;
  margin-left: 0;
  padding-left: 0;
}

.fe-richtext-popup-view {
  min-height: 100px;
  max-height: 360px;
  overflow-y: auto;
  padding: 0.375rem 0.75rem;
  line-height: 1.5;
  color: var(--blue-5);
  overflow-wrap: anywhere;
}

.fe-richtext-popup-view p,
.fe-richtext-popup-view ol,
.fe-richtext-popup-view ul {
  margin: 0;
}

.fe-richtext-popup-view ol,
.fe-richtext-popup-view ul {
  padding-left: 1.5em;
}

.fe-richtext-popup-view--readonly {
  background-color: var(--bs-secondary-bg, #e9ecef);
  color: var(--bs-secondary-color, #6c757d);
  cursor: default;
}
