// Lexical Editor Component
.lbaic-settings-lexical-editor {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 1px solid var(--lbaic-settings-lexical-editor-border);
  border-radius: 6px;
  background-color: var(--lbaic-settings-white);

  &:focus-within {
    border-color: rgba(var(--lbaic-settings-primary-rgb), 0.3);
    box-shadow: 0 0 0 3px rgba(var(--lbaic-settings-primary-rgb), 0.2);
  }

  &-error {
    --lbaic-settings-lexical-editor-border: var(--lbaic-settings-lexical-editor-error);
    --lbaic-settings-lexical-editor-placeholder-color: var(--lbaic-settings-lexical-editor-error);

    &:focus-within {
      --lbaic-settings-lexical-editor-border: var(--lbaic-settings-lexical-editor-error);
      --lbaic-settings-lexical-editor-placeholder-color: var(--lbaic-settings-lexical-editor-error);
    }

    &-message {
      padding-block-start: 4px;

      &-in {
        font-size: var(--lbaic-settings-fs-12);
        font-weight: var(--lbaic-settings-fw-500);
        color: var(--lbaic-settings-lexical-editor-error);
        line-height: var(--lbaic-settings-lh-16);
      }
    }
  }

  &-label {
    height: var(--lbaic-settings-input-placeholder-height, 100%);
    display: flex;
    align-items: center;
    margin-block-end: 5px;

    &-in {
      padding-inline: var(--lbaic-settings-input-placeholder-padding-inline);
      font-size: var(--lbaic-settings-fs-14);
      font-weight: var(--lbaic-settings-fw-500);
      line-height: var(--lbaic-settings-lh-18);
      cursor: pointer;
    }
  }
}

// Toolbar
.lbaic-settings-lexical-toolbar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-bottom: 1px solid var(--lbaic-settings-input-border, #d1d5db);
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  background-color: rgba(249, 250, 251, 0.6);
  overflow-x: auto;
  overflow-y: hidden;

  &::-webkit-scrollbar {
    height: 6px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    border-radius: 3px;
    background-color: #d1d5db;

    &:hover {
      background-color: #9ca3af;
    }
  }
}

.lbaic-settings-lexical-toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.lbaic-settings-lexical-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lbaic-settings-lexical-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #4b5563;
  cursor: pointer;
  transition: background-color 180ms ease-in-out, color 180ms ease-in-out;

  &:hover {
    background-color: #f3f4f6;
  }

  &.active {
    background-color: #e5e7eb;
    color: #111827;
  }

  &:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
}

.lbaic-settings-lexical-toolbar-separator {
  width: 1px;
  height: 20px;
  margin-left: 4px;
  margin-right: 4px;
  background-color: #e5e7eb;
}

.lbaic-settings-lexical-toolbar-emoji {
  .lbaic-settings-emoji {
    width: 32px;
    height: 32px;
    display: block;

    &:hover {
      --lbaic-settings-emoji-action-bg: #f3f4f6;
    }
  }
}

.lbaic-settings-lexical-toolbar-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.lbaic-settings-lexical-toolbar-icon-sm {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

// Dropdown
.lbaic-settings-lexical-toolbar-dropdown {
  position: relative;
}

.lbaic-settings-lexical-toolbar-dropdown-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #4b5563;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 180ms ease-in-out;

  &:hover {
    background-color: #f3f4f6;
  }
}

.lbaic-settings-lexical-toolbar-dropdown-label {
  font-size: 12px;
}

.lbaic-settings-lexical-toolbar-dropdown-menu {
  position: absolute;
  top: var(--lbaic-settings-dropdown-top);
  left: var(--lbaic-settings-dropdown-left);
  min-width: 160px;
  width: min-content;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background-color: var(--lbaic-settings-white);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  z-index: 50;
  overflow: hidden;
}

.lbaic-settings-lexical-toolbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: #111827;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background-color 180ms ease-in-out;

  &:hover {
    background-color: #f3f4f6;
  }

  &-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  &-h1 {
    font-size: 20px;
    font-weight: 700;
  }

  &-h2 {
    font-size: 18px;
    font-weight: 700;
  }

  &-h3 {
    font-weight: 700;
  }

  &-quote {
    font-style: italic;
  }

  &-code {
    font-family: monospace;
  }
}

// Word Count
.lbaic-settings-lexical-word-count {
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
}

// Editor Content Area
.lbaic-settings-lexical-editor-content {
  position: relative;
  height: 250px;
  min-height: 150px;
  max-height: 594px;
  overflow-y: auto;
  resize: vertical;
}

.lbaic-settings-lexical-editor-input {
  width: 100%;
  height: max-content;
  min-height: 150px;
  max-width: none;
  padding: 12px 12px 24px 12px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.75;
  color: #111827;
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;

  &:focus {
    outline: none;
  }

  * {
    line-height: 1.75;
    font-size: var(--lbaic-settings-fs-13);
  }

  h1 {
    &, * {
      font-size: var(--lbaic-settings-fs-22);
    }
  }

  h2 {
    &, * {
      font-size: var(--lbaic-settings-fs-22);
    }
  }

  h3 {
    &, * {
      font-size: var(--lbaic-settings-fs-18);
    }
  }

  h4 {
    &, * {
      font-size: var(--lbaic-settings-fs-16);
    }
  }

  h5 {
    &, * {
      font-size: var(--lbaic-settings-fs-14);
    }
  }

  h6 {
    &, * {
      font-size: var(--lbaic-settings-fs-12);
    }
  }

  h1, h2, h3, h4, h5, h6 {
    &, * {
      color: currentColor;
      line-height: normal;
    }
  }
}

.lbaic-settings-lexical-editor-placeholder {
  position: absolute;
  top: 28px;
  left: 12px;
  font-size: 14px;
  color: #9ca3af;
  pointer-events: none;
  user-select: none;
}

// Text Formatting (inline styles applied to text nodes)
.lbaic-settings-lexical-text-bold {
  font-weight: 700;
}

.lbaic-settings-lexical-text-italic {
  font-style: italic;
}

.lbaic-settings-lexical-text-underline {
  text-decoration: underline;
}

.lbaic-settings-lexical-text-strikethrough {
  text-decoration: line-through;
}

.lbaic-settings-lexical-text-code {
  padding: 0 4px;
  padding-top: 2px;
  padding-bottom: 2px;
  border-radius: 3px;
  background-color: #f3f4f6;
  font-family: monospace;
  font-size: 12px;
}

// Headings (block-level elements)
.lbaic-settings-lexical-h1 {
  margin-bottom: 8px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
}

.lbaic-settings-lexical-h2 {
  margin-bottom: 8px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
}

.lbaic-settings-lexical-h3 {
  margin-bottom: 4px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

// Paragraph
.lbaic-settings-lexical-paragraph {
  margin-bottom: 4px;
}

// Quote
.lbaic-settings-lexical-quote {
  margin-top: 8px;
  margin-bottom: 8px;
  padding-left: 16px;
  border-left: 4px solid #d1d5db;
  font-style: italic;
  color: #4b5563;
}

// Lists
.lbaic-settings-lexical-ol {
  margin-left: 16px;
  padding-left: 16px;
  list-style-type: decimal;
  list-style-position: outside;
}

.lbaic-settings-lexical-ul {
  margin-left: 16px;
  padding-left: 16px;
  list-style-type: disc;
  list-style-position: outside;
}

.lbaic-settings-lexical-listitem {
  margin: 2px 0;
}

.lbaic-settings-lexical-listitem-nested {
  list-style-type: none;
}

// Link
.lbaic-settings-lexical-link {
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;

  &:hover {
    color: #1d4ed8;
  }
}

// Code Block
.lbaic-settings-lexical-code-block {
  display: block;
  margin-top: 8px;
  margin-bottom: 8px;
  padding: 12px;
  border-radius: 6px;
  background-color: #111827;
  color: #f3f4f6;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

// Alignment support
[dir="ltr"] .lbaic-settings-lexical-editor {
  .lbaic-settings-lexical-paragraph,
  .lbaic-settings-lexical-h1,
  .lbaic-settings-lexical-h2,
  .lbaic-settings-lexical-h3,
  .lbaic-settings-lexical-quote {
    &[style*="text-align: left"] {
      text-align: left !important;
    }

    &[style*="text-align: center"] {
      text-align: center !important;
    }

    &[style*="text-align: right"] {
      text-align: right !important;
    }

    &[style*="text-align: justify"] {
      text-align: justify !important;
    }
  }
}
