:root {
  /* Lexxy resolves colour variables outside the editor, so keep these on :root. */
  --highlight-9: var(--color-foreground);
  --highlight-5: var(--color-brand-mid);
  --highlight-3: var(--color-destructive);
  --highlight-7: var(--color-success);
  --highlight-bg-1: var(--color-construction-bg);
  --highlight-bg-5: color-mix(in srgb, var(--color-brand-mid) 12%, white);
}

.lexxy-content,
lexxy-editor {
  --lexxy-font-base: var(--font-sans);
  --lexxy-font-mono: var(--font-mono);
  --lexxy-color-ink: var(--color-foreground);
  --lexxy-color-ink-light: var(--color-gray-600);
  --lexxy-color-ink-lighter: var(--color-gray-300);
  --lexxy-color-ink-lightest: var(--color-gray-100);
  --lexxy-color-canvas: white;
  --lexxy-color-link: var(--color-info);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.5rem;
  overflow-wrap: anywhere;
  min-width: 0;
}

.lexxy-content :is(h2, h3, h4) {
  font-family: var(--font-display);
  line-height: 1.4;
}

.lexxy-content h2 { font-size: 1.25rem; }
.lexxy-content h3 { font-size: 1.125rem; }
.lexxy-content h4 { font-size: 1rem; }

.lexxy-content hr {
  border: 0;
  border-top: 1px solid var(--color-gray-300);
  margin-block: 1rem;
}

[data-project-site-panel] lexxy-editor {
  min-width: 0;
  border: 0;
  border-radius: 0 0 0.75rem 0.75rem;
  background: white;
  --lexxy-focus-ring-color: var(--color-brand);
  --lexxy-toolbar-button-size: 2rem;
  --lexxy-toolbar-gap: 1px;
  --lexxy-toolbar-spacing: .25rem;
}

[data-project-site-panel] .lexxy-editor__content {
  min-height: 10rem;
  padding: 1rem;
}

[data-project-site-panel] .lexxy-editor__toolbar {
  padding: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

/* Before Lexxy starts, it reserves toolbar + 8 rows. Reserve our real size instead, so the page
   does not jump when the editor appears. */
[data-project-site-panel] lexxy-editor:not(:defined) {
  min-block-size: calc(var(--lexxy-toolbar-height) + 10rem);
}

.team-mention {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 0.375rem;
  padding: 0.2rem 0.375rem;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--color-brand-mid) 10%, transparent);
  color: var(--color-foreground);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1rem;
  vertical-align: middle;
}

/* Lexxy wraps the chip in a baseline-aligned inline-flex attachment, so centre the wrapper on the line too. */
action-text-attachment:has(> .team-mention) {
  vertical-align: middle;
}

.team-mention__avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  overflow: hidden;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--color-brand), var(--color-brand-mid), var(--color-brand-end));
  color: white;
  font-size: 0.5rem;
}

/* Override Lexxy's 1em custom-attachment images, including their logical sizes. */
.team-mention .team-mention__avatar img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  object-fit: cover;
}

.team-mention__name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.voice-note-panel { margin: .75rem; padding: .75rem 1rem; border: 1px solid var(--color-border); border-radius: .5rem; background: var(--color-editor-panel); }
.voice-note-status { display: flex; justify-content: space-between; gap: 1rem; font-size: .75rem; }
.voice-note-progress { display: block; appearance: none; width: 100%; height: .25rem; margin-bottom: .75rem; border: 0; border-radius: 999px; overflow: hidden; background: var(--color-border); color: var(--color-destructive); }
.voice-note-progress::-webkit-progress-bar { background: var(--color-border); }
.voice-note-progress::-webkit-progress-value { background: var(--color-destructive); border-radius: 999px; }
.voice-note-progress::-moz-progress-bar { background: var(--color-destructive); border-radius: 999px; }
lexxy-toolbar .voice-note-record.is-recording { background: var(--color-destructive); color: white; border-radius: 999px; animation: voice-note-glow 1.6s ease-in-out infinite; }
.voice-note-stop-icon { display: block; width: .625rem; height: .625rem; margin: auto; background: currentColor; border-radius: 2px; }
@keyframes voice-note-glow { 0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-destructive) 15%, transparent); } 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-destructive) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { lexxy-toolbar .voice-note-record.is-recording { animation: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-destructive) 20%, transparent); } }
.voice-note-error { color: var(--color-destructive); font-size: .875rem; padding-inline: 1rem; }
.voice-note-error:not(:empty) { padding-block: .75rem; }
.lexxy-content audio { width: 100%; max-width: 28rem; border-radius: 999px; background: var(--color-editor-panel); }
.lexxy-content audio::-webkit-media-controls-panel { background: var(--color-editor-panel); }
.voice-note-attachment { max-width: 100%; padding: .5rem; }
lexxy-toolbar .voice-note-record { width: var(--lexxy-toolbar-button-size); padding-inline: .5rem; }

/* Reserve removal space so revealing the control never moves the player. */
lexxy-editor .attachment[data-content-type^="audio/"] { max-width: 32rem; padding-inline-end: 3.5rem; }
lexxy-editor .attachment[data-content-type^="audio/"] audio { max-width: none; }

lexxy-editor .attachment[data-content-type^="audio/"] lexxy-node-delete-button {
  opacity: 1;
  pointer-events: auto;
}

lexxy-editor .attachment[data-content-type^="audio/"] .lexxy-floating-controls__group {
  background: transparent;
  padding: 0;
}

lexxy-editor .attachment[data-content-type^="audio/"] .lexxy-node-delete {
  block-size: 2.5rem;
  inline-size: 2.5rem;
  min-block-size: 2.5rem;
  min-inline-size: 2.5rem;
  border-radius: .5rem;
  background: transparent;
  color: var(--color-muted-foreground);
  cursor: pointer;
  transition: background-color .15s, color .15s, transform .15s;
}

lexxy-editor .attachment[data-content-type^="audio/"] .lexxy-node-delete:hover {
  background: color-mix(in srgb, var(--color-destructive) 10%, transparent);
  color: var(--color-destructive);
}

lexxy-editor .attachment[data-content-type^="audio/"] .lexxy-node-delete:active { transform: scale(.98); }

lexxy-editor .attachment[data-content-type^="audio/"] .lexxy-node-delete:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  lexxy-editor .attachment[data-content-type^="audio/"] lexxy-node-delete-button {
    opacity: 0;
    pointer-events: none;
  }

  lexxy-editor .attachment[data-content-type^="audio/"]:is(:hover, :focus-within, .node--selected) lexxy-node-delete-button {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Includes hybrid devices with a mouse and a touch screen. */
@media (any-pointer: coarse) {
  lexxy-editor .attachment[data-content-type^="audio/"] lexxy-node-delete-button {
    opacity: 1;
    pointer-events: auto;
  }
}

lexxy-editor.visit-description-editor {
  border: 1.5px solid var(--color-input);
  border-radius: 0.5rem;
  --lexxy-focus-ring-color: var(--color-brand);
}

.visit-description-editor .lexxy-editor__content {
  min-height: 8rem;
  padding: 0.75rem;
}

lexxy-editor.visit-description-editor:not(:defined) {
  min-block-size: calc(var(--lexxy-toolbar-height) + 8rem + 2 * 1.5px);
}

lexxy-editor.comment-editor {
  border: 0;
  border-radius: .375rem .375rem 0 0;
  background: transparent;
  --lexxy-focus-ring-color: transparent;
  --lexxy-toolbar-button-size: 2rem;
  --lexxy-toolbar-gap: 1px;
  --lexxy-toolbar-spacing: .25rem;
  --lexxy-toolbar-padding: 1px;
}

.comment-editor > lexxy-toolbar {
  --lexxy-toolbar-icon-size: .875rem;
  padding: .375rem .75rem;
  border-color: var(--color-border);
  font-size: .875rem;
  line-height: 1.25rem;
}

/* Phones: tighter edges leave room for the overflow menu button beside the tools that always stay. */
@media (width < 40rem) {
  .comment-editor > lexxy-toolbar { padding-inline: .375rem; }
}

.comment-editor .lexxy-editor__content {
  min-height: 6rem;
  padding: 1rem .75rem;
}

/* Once files are attached the list below gives the box its height, so the empty writing space shrinks. */
[data-comment-editor]:has([data-comment-form-staged], [data-existing-comment-file]:not([hidden])) .comment-editor .lexxy-editor__content {
  min-height: 2.5rem;
  padding-bottom: .5rem;
}

/* Contain the first layout frame while Lexxy moves extra tools into its overflow menu. */
:is(.comment-editor, [data-project-site-panel] lexxy-editor) > lexxy-toolbar:not(:has([aria-expanded="true"])) {
  overflow: clip;
  overflow-clip-margin: 3px;
}

/* Files use the shared Attach controls; rich-text attachments are mentions and voice notes. */
:is(.comment-editor, [data-project-site-panel] lexxy-editor) lexxy-toolbar button:is([name="image"], [name="file"]) {
  display: none;
}


.comment-editor .lexxy-prompt-menu {
  inline-size: 22rem;
  min-inline-size: 0;
  max-inline-size: calc(100% - 1rem);
  padding: .25rem;
  border: 1px solid var(--color-border);
  border-radius: .5rem;
  box-shadow: var(--shadow-elevated);
}

.comment-editor .lexxy-prompt-menu__item {
  gap: .625rem;
  padding: .5rem .75rem;
  overflow-wrap: break-word;
}

.comment-editor .lexxy-prompt-menu__item[aria-selected] {
  background: var(--color-secondary);
}

/* Neyra's attachment icons use strokes rather than Lexxy's filled glyphs. */
lexxy-toolbar [data-comment-attachment-tool] svg { fill: none; }

/* One author-to-content gap, regardless of the first content type. */
[data-comment-content] > [data-comment-attachments] { margin-top: 0; }
[data-comment-content] .lexxy-content > :first-child,
[data-comment-content] .lexxy-content .action-text-content > :first-child { margin-top: 0; }
[data-comment-content] .lexxy-content > :last-child,
[data-comment-content] .lexxy-content .action-text-content > :last-child { margin-bottom: 0; }
[data-comment-content] .voice-note-attachment { padding-block: 0; }
[data-comment-content] audio { display: block; }
/* The audio-player controller swaps this for its own 2.75rem player; the same height keeps the page still. */
[data-comment-content] audio[controls] { height: 2.75rem; }

/* Give recordings breathing room within mixed text/audio updates. */
[data-comment-content] .action-text-content > :is(action-text-attachment, figure):has(audio) {
  display: block;
  margin-block: 1.25rem;
}
[data-comment-content] .action-text-content > :is(action-text-attachment, figure):has(audio):first-child { margin-top: 0; }
[data-comment-content] .action-text-content > :is(action-text-attachment, figure):has(audio):last-child { margin-bottom: 0; }

/* Notes stay in the autosaving editor; only its editing chrome changes with focus.
   Toolbar menus are descendants, so using them keeps the whole editor active. */
.quote-notes-editor:not(:focus-within) > lexxy-toolbar {
  display: none;
}

/* The editor is the card body, with consistent padding in both states. */
.quote-notes-editor .lexxy-editor__content {
  min-height: 6rem;
  padding: .75rem 1rem;
}

.quote-notes-editor > lexxy-toolbar {
  margin-top: .5rem;
  padding-inline: 1rem;
}

/* The final paragraph must not add space below the notes or its placeholder. */
.quote-notes-editor .lexxy-editor__content > :last-child {
  margin-block-end: 0;
}
