/*
 * F-235 — CallMeBacker's editor skin.
 *
 * Replaces the stock Trix stylesheet Rails ships (the grey 1990s button
 * strip) with the same visual language as the rest of the admin: white
 * card, gray-300 hairline, yellow focus ring, 2rem tap targets. Trix is
 * untouched underneath — this is CSS plus the custom toolbar markup in
 * app/javascript/lib/trix_toolbar.js. Nothing about ActionText storage,
 * sanitization or attachments changes.
 *
 * TOKENS: overridable per surface via --editor-*. Defaults match the admin
 * light theme; a dark surface can restyle by setting them on a wrapper
 * rather than by fighting selectors.
 */
:root {
  --editor-surface:      #ffffff;
  --editor-toolbar-bg:   #f9fafb;
  --editor-edge:         #d1d5db;
  --editor-edge-soft:    #e5e7eb;
  --editor-ink:          #111827;
  --editor-ink-soft:     #4b5563;
  --editor-ink-faint:    #9ca3af;
  --editor-ring:         rgba(250, 204, 21, 0.45);  /* yellow-400, the admin focus ring */
  --editor-accent:       #111827;
  --editor-radius:       0.75rem;
}

trix-toolbar * { box-sizing: border-box; }

/* ── The card: toolbar and editor read as ONE control ────────────────────
   They're siblings in the DOM, so the rounding is split between them and
   the shared border is drawn once. */
trix-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--editor-toolbar-bg);
  border: 1px solid var(--editor-edge);
  border-bottom: 0;
  border-radius: var(--editor-radius) var(--editor-radius) 0 0;
  padding: 0.3rem 0.4rem;
}

trix-toolbar .trix-button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
}

trix-toolbar .trix-button-group {
  display: flex;
  align-items: center;
  gap: 0.1rem;
}

/* Hairline between groups instead of boxed button clusters. */
trix-toolbar .trix-button-group + .trix-button-group {
  margin-left: 0.35rem;
  padding-left: 0.45rem;
  border-left: 1px solid var(--editor-edge-soft);
}

trix-toolbar .trix-button-group--history { margin-left: auto; }

/* Sized for BOTH toolbars. The custom one (F-235) renders inline SVG and
   wants a 2rem square; stock Trix renders the button's TEXT label ("Bold",
   "Attach Files") and hides it behind a background-image icon with rules
   this sheet doesn't carry. Fixed-width buttons turn those labels into the
   overlapping mess Scott hit on 2026-09-25. Auto width with a min keeps the
   icons square and lets the words be words. */
trix-toolbar .trix-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  white-space: nowrap;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--editor-ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

trix-toolbar .trix-button svg {
  width: 1.05rem;
  height: 1.05rem;
  pointer-events: none;   /* clicks land on the button, never the glyph */
}

trix-toolbar .trix-button:hover { background: #eef0f3; color: var(--editor-ink); }
trix-toolbar .trix-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--editor-ring);
}

/* Trix marks the live formats. Filled, not tinted — at a glance, across
   a room, on a laptop that's been in the sun all morning. */
trix-toolbar .trix-button.trix-active {
  background: var(--editor-accent);
  color: #ffffff;
}

trix-toolbar .trix-button:disabled {
  opacity: 0.3;
  cursor: default;
  background: transparent;
  color: var(--editor-ink-soft);
}

trix-editor {
  display: block;
  min-height: 8rem;
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--editor-surface);
  border: 1px solid var(--editor-edge);
  border-radius: 0 0 var(--editor-radius) var(--editor-radius);
  color: var(--editor-ink);
  font-size: 0.95rem;
  line-height: 1.6;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

trix-editor:focus {
  border-color: #facc15;
  box-shadow: 0 0 0 3px var(--editor-ring);
}

trix-editor:empty:not(:focus)::before {
  content: attr(placeholder);
  color: var(--editor-ink-faint);
}

/* A short field shouldn't open a canyon. Opt in with
   <%= f.rich_text_area :rate, class: "editor--compact" %>. */
trix-editor.editor--compact { min-height: 4.5rem; }

/* ── The link dialog — the single ugliest thing in stock Trix ──────────── */
trix-toolbar .trix-dialogs { position: relative; }

trix-toolbar .trix-dialog {
  position: absolute;
  top: 0.4rem;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 0.75rem;
  background: var(--editor-surface);
  border: 1px solid var(--editor-edge);
  border-radius: 0.6rem;
  box-shadow: 0 10px 25px -5px rgba(17, 24, 39, 0.18);
}

trix-toolbar .trix-dialog__link-fields {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

trix-toolbar .trix-input--dialog {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--editor-edge);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  color: var(--editor-ink);
  background: #fff;
}

trix-toolbar .trix-input--dialog:focus {
  outline: none;
  border-color: #facc15;
  box-shadow: 0 0 0 3px var(--editor-ring);
}

trix-toolbar .trix-button--dialog {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--editor-edge);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--editor-ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

trix-toolbar .trix-button--dialog:hover { background: #f3f4f6; color: var(--editor-ink); }

trix-toolbar .trix-button--dialog[data-trix-method="setAttribute"] {
  background: var(--editor-accent);
  border-color: var(--editor-accent);
  color: #fff;
}

trix-toolbar .trix-button--dialog[data-trix-method="setAttribute"]:hover { background: #374151; }

trix-toolbar .trix-dialog--link .trix-validate:invalid { border-color: #ef4444; }

/* ── Rendered content ────────────────────────────────────────────────────
   Used by the EDITOR and by every place a brief is displayed, including
   the public submission form's white card on a dark page. So: colors
   inherit, only structure is asserted. Set a color here and the public
   form goes grey-on-grey the next time that page is restyled. */
.trix-content,
trix-editor {
  word-break: break-word;
}

.trix-content > *:first-child, trix-editor > *:first-child { margin-top: 0; }
.trix-content > *:last-child,  trix-editor > *:last-child  { margin-bottom: 0; }

.trix-content h1, trix-editor h1 {
  margin: 1.1em 0 0.45em;
  font-size: 1.2em;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.trix-content p, trix-editor p { margin: 0 0 0.75em; }

.trix-content ul, .trix-content ol,
trix-editor ul, trix-editor ol {
  margin: 0 0 0.75em;
  padding-left: 1.35em;
}

.trix-content ul, trix-editor ul { list-style: disc; }
.trix-content ol, trix-editor ol { list-style: decimal; }
.trix-content li, trix-editor li { margin: 0.15em 0; }

/* Trix nests a fresh <ul>/<ol> inside an <li> for indented levels. */
.trix-content li > ul, .trix-content li > ol,
trix-editor li > ul, trix-editor li > ol { margin-bottom: 0; }

.trix-content blockquote, trix-editor blockquote {
  margin: 0 0 0.75em;
  padding: 0.15em 0 0.15em 0.9em;
  border-left: 3px solid var(--editor-edge);
  font-style: italic;
  opacity: 0.9;
}

.trix-content a, trix-editor a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.trix-content pre, trix-editor pre {
  margin: 0 0 0.75em;
  padding: 0.6em 0.8em;
  border-radius: 0.5rem;
  background: rgba(17, 24, 39, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  white-space: pre-wrap;
}

.trix-content img, trix-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}

/* ── Attachments ─────────────────────────────────────────────────────────
   Rails needs these gallery overrides to accommodate the
   <action-text-attachment> wrapper; without them gallery images get
   squished by the max-width: 33% rule. Carried over verbatim in intent
   from the stock sheet — do not drop them. */
.trix-content .attachment {
  display: inline-block;
  position: relative;
  max-width: 100%;
}

.trix-content .attachment a { color: inherit; text-decoration: none; }
.trix-content .attachment__caption { text-align: center; font-size: 0.9em; opacity: 0.75; }
.trix-content .attachment__caption .attachment__name + .attachment__size::before { content: ' \2022 '; }
.trix-content .attachment--preview { width: 100%; text-align: center; }

.trix-content .attachment--file {
  margin: 0 2px 2px 2px;
  padding: 0.4em 1em;
  border: 1px solid var(--editor-edge);
  border-radius: 0.5rem;
  line-height: 1;
}

.trix-content .attachment-gallery { display: flex; flex-wrap: wrap; position: relative; }

.trix-content .attachment-gallery > action-text-attachment,
.trix-content .attachment-gallery > .attachment {
  flex: 1 0 33%;
  padding: 0 0.5em;
  max-width: 33%;
}

.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment,
.trix-content .attachment-gallery.attachment-gallery--2 > .attachment,
.trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment,
.trix-content .attachment-gallery.attachment-gallery--4 > .attachment {
  flex-basis: 50%;
  max-width: 50%;
}

.trix-content action-text-attachment .attachment {
  padding: 0 !important;
  max-width: 100% !important;
}

/* Upload progress bar on a dropped image. */
trix-editor .attachment__progress {
  position: absolute;
  z-index: 1;
  height: 0.25rem;
  top: calc(50% - 0.125rem);
  left: 8%;
  width: 84%;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.15);
  opacity: 0.95;
  transition: opacity 200ms ease-in;
}

trix-editor .attachment__progress[value="100"] { opacity: 0; }

@media (max-width: 640px) {
  trix-toolbar .trix-button { min-width: 2.25rem; height: 2.25rem; }   /* thumbs, not cursors */
  trix-toolbar .trix-button-group--history { margin-left: 0; }
}

/* ── Trix internals — FUNCTIONAL, not cosmetic ───────────────────────────
   Carried over from the stock sheet. Caret behavior around attachments
   depends on these: without the cursor-target rules the caret can't be
   placed beside an attachment, and without the selection rules the
   mutable wrappers paint their own highlight over yours. They look
   deletable and are not. */
trix-editor [data-trix-mutable]:not(.attachment__caption-editor) { user-select: none; }

trix-editor [data-trix-mutable]::selection,
trix-editor [data-trix-cursor-target]::selection,
trix-editor [data-trix-mutable] ::selection { background: none; }

trix-editor .attachment__caption-editor:focus::selection { background: highlight; }

trix-editor [data-trix-cursor-target] {
  display: inline !important;
  width: 0 !important;
  padding: 0 !important;
}

trix-editor .attachment { position: relative; }
trix-editor .attachment:hover { cursor: default; }
trix-editor .attachment--preview .attachment__caption:hover { cursor: text; }

trix-editor .attachment--file[data-trix-mutable] {
  box-shadow: 0 0 0 2px highlight;
  border-color: transparent;
}

trix-editor .attachment__toolbar {
  position: absolute;
  z-index: 1;
  top: -0.9em;
  left: 0;
  width: 100%;
  text-align: center;
}
