/* Lexxy, the site's one rich text editor (RichTextEditorHelper, docs/prd.lexxy-everywhere.md
   decisions 3, 4 and 7), in the app's own light-dark tokens. Applies to every
   editor; its own stylesheet is added by rich_text_editor_controller.js on a
   page that holds one. */
lexxy-editor.rich-text-editor {
  --lexxy-color-canvas: var(--surface-elevated);
  --lexxy-color-text: var(--page-text);
  --lexxy-color-text-subtle: var(--text-muted);
  --lexxy-color-ink: var(--page-text);
  --lexxy-color-ink-medium: var(--text-muted);
  --lexxy-color-ink-light: var(--text-muted);
  --lexxy-color-ink-lighter: var(--border);
  --lexxy-color-ink-lightest: var(--surface);
  --lexxy-color-ink-inverted: var(--surface-elevated);
  --lexxy-color-link: var(--admin-inline-link);
  --lexxy-color-accent-dark: var(--pill-blue-text);
  --lexxy-color-accent-light: var(--pill-blue-bg);
  --lexxy-color-accent-lightest: var(--pill-blue-bg);
  --lexxy-color-selected: var(--pill-blue-bg);
  --lexxy-color-selected-hover: var(--pill-blue-bg);
  --lexxy-color-code-bg: var(--surface);
  --lexxy-color-table-header-bg: var(--surface);
  --lexxy-color-table-cell-border: var(--border);
  --lexxy-font-base: inherit;
  --lexxy-shadow: var(--card-shadow);

  display: block;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-elevated);
  color: var(--page-text);
  box-shadow: var(--dashboard-filter-shadow);

  &:focus-within {
    border-color: var(--pill-blue-text);
    box-shadow: 0 0 0 3px var(--input-ring-default);
  }

  /* A form that came back with an error on this field. */
  &[data-invalid] {
    border-color: var(--notice-error-border);
  }

  & lexxy-toolbar {
    border-bottom: 1px solid var(--border);
    border-radius: 0.75rem 0.75rem 0 0;
    background: var(--surface-elevated);
  }

  & .lexxy-editor__content {
    min-height: 9rem;
    padding: 0.75rem 1rem;
    outline: none;
  }

  /* Coloured text needs a style attribute, which no body keeps
     (config/initializers/action_text.rb), and underline reads as a link. */
  & .lexxy-editor__toolbar-dropdown--highlight,
  & button[name="underline"] {
    display: none;
  }

  /* A picture whose file does not load (a Trix-era one whose upload is gone)
     would be an image 0px high over an empty caption, with nothing to click.
     The box gives it a place to click, to select it and delete it. */
  & figure.attachment .attachment__container {
    min-height: 2.5rem;
    border-radius: 0.5rem;
    background: var(--surface);
  }

  /* A table and a divider are not what makers write with. */
  &[data-preset="text"],
  &[data-preset="listing_images"] {
    & button[name="table"],
    & button[name="divider"] {
      display: none;
    }
  }

  /* A review and a reply hold bold, italic and lists (a reply a link too), so
     every other button goes, undo and redo included (Cmd+Z still works). The
     toolbar's children are buttons and dropdown elements: what is not named
     here is hidden. */
  &[data-preset="review"] lexxy-toolbar > :not(button[name="bold"], button[name="italic"], button[name="unordered-list"], button[name="ordered-list"]),
  &[data-preset="reply"] lexxy-toolbar > :not(button[name="bold"], button[name="italic"], button[name="unordered-list"], button[name="ordered-list"], lexxy-link-dropdown) {
    display: none;
  }

  &[data-preset="review"] .lexxy-editor__content,
  &[data-preset="reply"] .lexxy-editor__content {
    min-height: 5rem;
  }
}

/* The blog's own sizes: a long page of writing, its toolbar kept in view while
   it scrolls. Below md the app's own top bar is sticky (shared/_app_sidebar),
   so the toolbar sits under that bar. */
lexxy-editor.blog-prose {
  & lexxy-toolbar {
    position: sticky;
    top: 3.5rem;
    z-index: 10;

    @media (min-width: 768px) {
      top: 0;
    }
  }

  & .lexxy-editor__content {
    min-height: 24rem;
    padding: 1.25rem 1rem 2rem;

    @media (min-width: 640px) {
      padding: 2rem 2.5rem 3rem;
    }
  }
}
