/* Lexxy Rich Text Editor Styles
 * Based on 37signals/Fizzy implementation
 * Adapted for Tailwind CSS variables
 */

/* Editor Container */
lexxy-editor {
  display: block;
  position: relative;
  overflow: visible;
}

lexxy-editor figure.node--selected {
  outline: 2px solid rgb(99 102 241); /* indigo-500 */
  outline-offset: 2px;
}

lexxy-editor figure.node--selected:has(img) img {
  outline: 2px solid rgb(99 102 241);
  outline-offset: 2px;
}

/* Empty state placeholder */
lexxy-editor.lexxy-editor--empty .lexxy-editor__content:not(:has(ul, ol))::before {
  content: attr(placeholder);
  color: currentColor;
  cursor: text;
  opacity: 0.5;
  pointer-events: none;
  position: absolute;
  white-space: pre-line;
}

/* Editor content area */
.lexxy-editor__content {
  margin: 0.5rem 0;
  min-height: 12rem;
  outline: 0;
}

.lexxy-editor__content *:first-child {
  margin-top: 0;
}

.lexxy-editor__content *:last-child {
  margin-bottom: 0;
}

/* Drag and drop state */
.lexxy-editor--drag-over {
  background-color: rgb(238 242 255); /* indigo-50 */
  border-radius: 0.25rem;
  outline: 2px dashed rgb(165 180 252); /* indigo-300 */
}

@media (prefers-color-scheme: dark) {
  .lexxy-editor--drag-over {
    background-color: rgb(30 27 75); /* indigo-950 */
    outline-color: rgb(99 102 241); /* indigo-500 */
  }
}

/* Toolbar */
lexxy-toolbar {
  --lexxy-toolbar-icon-size: 1.25rem;

  background-color: white;
  border-bottom: 1px solid rgb(229 231 235); /* gray-200 */
  color: currentColor;
  display: flex;
  flex-wrap: wrap;
  font-size: inherit;
  gap: 0.25rem;
  margin: 0;
  max-width: 100%;
  padding: 0.5rem;
  position: relative;
  position: sticky;
  top: 0;
  z-index: 10;
  border-radius: 0.5rem 0.5rem 0 0;
}

@media (prefers-color-scheme: dark) {
  lexxy-toolbar {
    background-color: rgb(31 41 55); /* gray-800 */
    border-bottom-color: rgb(55 65 81); /* gray-700 */
  }
}

lexxy-toolbar dialog {
  background-color: white;
  border: 1px solid rgb(229 231 235);
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  color: rgb(17 24 39);
  padding: 1rem;
  position: absolute;
  z-index: 20;
}

@media (prefers-color-scheme: dark) {
  lexxy-toolbar dialog {
    background-color: rgb(31 41 55);
    border-color: rgb(55 65 81);
    color: rgb(243 244 246);
  }
}

/* Toolbar buttons */
.lexxy-editor__toolbar-button {
  --toolbar-button-size: 2.5rem;

  appearance: none;
  aspect-ratio: 1;
  background-color: transparent;
  height: var(--toolbar-button-size);
  border: none;
  border-radius: 0.375rem;
  color: currentColor;
  cursor: pointer;
  display: grid;
  font-size: inherit;
  place-items: center;
}

.lexxy-editor__toolbar-button:is(:focus, :hover) {
  background-color: rgb(243 244 246); /* gray-100 */
  box-shadow: none;
}

@media (prefers-color-scheme: dark) {
  .lexxy-editor__toolbar-button:is(:focus, :hover) {
    background-color: rgb(55 65 81); /* gray-700 */
  }
}

.lexxy-editor__toolbar-button:is(:active),
.lexxy-editor__toolbar-button[aria-pressed="true"] {
  background-color: rgb(238 242 255); /* indigo-50 */
  color: rgb(79 70 229); /* indigo-600 */
}

@media (prefers-color-scheme: dark) {
  .lexxy-editor__toolbar-button:is(:active),
  .lexxy-editor__toolbar-button[aria-pressed="true"] {
    background-color: rgb(49 46 129); /* indigo-900 */
    color: rgb(165 180 252); /* indigo-300 */
  }
}

.lexxy-editor__toolbar-button svg {
  -webkit-touch-callout: none;
  height: var(--lexxy-toolbar-icon-size);
  fill: currentColor;
  grid-area: 1/1;
  width: var(--lexxy-toolbar-icon-size);
  user-select: none;
}

@media (min-width: 640px) {
  .lexxy-editor__toolbar-button {
    --toolbar-button-size: 2rem;
  }
}

.lexxy-editor__toolbar-overflow-menu {
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  display: flex;
  right: 0;
  padding: 0.25rem;
  position: absolute;
  z-index: 20;
}

@media (prefers-color-scheme: dark) {
  .lexxy-editor__toolbar-overflow-menu {
    background-color: rgb(31 41 55);
  }
}

.lexxy-editor__toolbar-spacer {
  flex: 1;
}

/* Code language picker */
.lexxy-code-language-picker {
  -webkit-appearance: none;
  appearance: none;
  background-color: white;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%236B7280'/%3E%3C/svg%3E");
  background-position: center right 0.75rem;
  background-repeat: no-repeat;
  background-size: 0.625rem;
  border: 1px solid rgb(209 213 219);
  border-radius: 0.375rem;
  color: rgb(55 65 81);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: inherit;
  margin: 0.25rem 0.25rem 0 0;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
  text-align: start;
}

@media (prefers-color-scheme: dark) {
  .lexxy-code-language-picker {
    background-color: rgb(55 65 81);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%23D1D5DB'/%3E%3C/svg%3E");
    border-color: rgb(75 85 99);
    color: rgb(209 213 219);
  }
}

/* Prompt Menu (Mention Autocomplete) */
.lexxy-prompt-menu {
  --lexxy-prompt-avatar-size: 1.5rem;
  --lexxy-prompt-min-width: 16rem;
  --lexxy-prompt-padding: 0.5rem;

  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  color: rgb(17 24 39);
  font-family: inherit;
  font-size: 0.875rem;
  list-style: none;
  margin: 0;
  min-width: var(--lexxy-prompt-min-width);
  padding: var(--lexxy-prompt-padding);
  visibility: hidden;
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}

@media (prefers-color-scheme: dark) {
  .lexxy-prompt-menu {
    background-color: rgb(31 41 55);
    color: rgb(243 244 246);
  }
}

.lexxy-prompt-menu--visible {
  visibility: visible;
}

.lexxy-prompt-menu__item {
  align-items: center;
  border-radius: 0.375rem;
  cursor: pointer;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  white-space: nowrap;
}

.lexxy-prompt-menu__item:hover {
  background-color: rgb(243 244 246);
}

@media (prefers-color-scheme: dark) {
  .lexxy-prompt-menu__item:hover {
    background-color: rgb(55 65 81);
  }
}

.lexxy-prompt-menu__item[aria-selected] {
  background-color: rgb(238 242 255);
}

@media (prefers-color-scheme: dark) {
  .lexxy-prompt-menu__item[aria-selected] {
    background-color: rgb(49 46 129);
  }
}

.lexxy-prompt-menu__item img {
  height: var(--lexxy-prompt-avatar-size);
  width: var(--lexxy-prompt-avatar-size);
  border-radius: 9999px;
  flex-shrink: 0;
  margin: 0;
  object-fit: cover;
}

.lexxy-prompt-menu__item + .lexxy-prompt-menu__item {
  margin-top: 2px;
}

/* Empty state */
.lexxy-prompt-menu__item--empty {
  color: rgb(107 114 128);
  padding: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  .lexxy-prompt-menu__item--empty {
    color: rgb(156 163 175);
  }
}

/* Mention styling in rendered content */
.mention {
  display: inline-flex;
  align-items: center;
  color: rgb(79 70 229); /* indigo-600 */
}

.mention:hover {
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  .mention {
    color: rgb(165 180 252); /* indigo-300 */
  }
}
