/* Selection comments ("Add to chat"), ported from the Control UI's chat.css / components.css
   (.chat-selection-popup, .chat-annotation-editor, .chat-comment-preview). Tokens come from
   composer-tokens.css, which these classes join. */

.chat-selection-popup,
.chat-annotation-editor,
.chat-comment-preview,
.chat-comment-tooltip,
.chat-comment-card {
  --shadow-lg: var(--overlay-shadow);
  box-sizing: border-box;
}

/* Toolbar over the selection */
.chat-selection-popup {
  z-index: 9999;
  padding: var(--menu-padding);
  border: 1px solid var(--overlay-border);
  border-radius: calc(var(--menu-radius) * var(--openclaw-corner-radius-scale));
  corner-shape: var(--chat-composer-corner-shape);
  background: var(--bg-elevated);
  box-shadow: var(--overlay-shadow);
  animation: selection-comment-fade-in .12s var(--ease-out);
  gap: 2px;
  display: flex;
  position: fixed;
}
.chat-selection-popup button {
  color: var(--text);
  min-height: 32px;
  border-radius: calc(var(--menu-item-radius) * var(--openclaw-corner-radius-scale));
  white-space: nowrap;
  background: none;
  border: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  display: flex;
  cursor: pointer;
}
.chat-selection-popup button:hover,
.chat-selection-popup button:focus-visible { background: var(--bg-hover); outline: none; }

@keyframes selection-comment-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Passages with an unsent comment: a soft mark until the message is sent */
::highlight(clawchats-comment-pending) {
  background: color-mix(in srgb, var(--accent-color) 15%, transparent);
}

/* The passage being edited, jumped to, or whose chip is hovered: clearly stronger than the
   pending tint, so it stands out among several pending passages */
::highlight(clawchats-comment),
::highlight(clawchats-comment-hover),
::highlight(clawchats-comment-jump) {
  background: color-mix(in srgb, var(--accent-color) 45%, transparent);
  color: var(--text-primary);
}

/* Comment box */
.chat-annotation-editor {
  z-index: 10000;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--popover);
  width: 380px;
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.5;
  display: grid;
  position: fixed;
  overflow: auto;
}
.chat-annotation-editor:has(textarea:focus) { border-color: color-mix(in srgb, var(--border) 94%, var(--text-strong)); }
.chat-annotation-editor textarea {
  overscroll-behavior: contain;
  scrollbar-width: thin;
  width: 100%;
  min-width: 0;
  min-height: 1lh;
  max-height: 5lh;
  color: inherit;
  font: inherit;
  resize: none;
  background: none;
  border: none;
  border-radius: 0;
  outline: none;
  margin-block: 3px;
  padding: 0;
  display: block;
  overflow-y: auto;
}
.chat-annotation-editor textarea::placeholder { color: var(--muted); }
.chat-annotation-editor__controls { display: none; }
.chat-annotation-editor--expanded textarea,
.chat-annotation-editor--expanded .chat-annotation-editor__controls { grid-column: 1 / -1; }
.chat-annotation-editor .btn.chat-annotation-editor__confirm { width: 28px; min-width: 28px; height: 28px; padding: 6px; }
.chat-annotation-editor.chat-annotation-editor--expanded .btn.chat-annotation-editor__confirm { display: none; }
.chat-annotation-editor--expanded .chat-annotation-editor__controls { justify-content: flex-end; gap: 6px; display: flex; }
.chat-annotation-editor .chat-annotation-editor__delete { margin-right: auto; }

/* Buttons (the Control UI's .btn family, scoped to these surfaces) */
:is(.chat-annotation-editor, .chat-comment-preview) .btn {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  min-height: 28px;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
  cursor: pointer;
}
:is(.chat-annotation-editor, .chat-comment-preview) .btn:hover { background: color-mix(in srgb, var(--text-primary) 12%, transparent); }
:is(.chat-annotation-editor, .chat-comment-preview) .btn:focus-visible { outline: 1px solid var(--muted); outline-offset: 2px; }
:is(.chat-annotation-editor, .chat-comment-preview) .btn.primary { background: var(--primary); color: var(--primary-foreground); }
:is(.chat-annotation-editor, .chat-comment-preview) .btn.primary:hover { background: var(--primary-hover); }
:is(.chat-annotation-editor, .chat-comment-preview) .btn--ghost { background: transparent; }
:is(.chat-annotation-editor, .chat-comment-preview) .btn--ghost:hover { background: var(--bg-hover); }
:is(.chat-annotation-editor, .chat-comment-preview) .btn--icon { width: 28px; min-width: 28px; height: 28px; padding: 6px; }
:is(.chat-annotation-editor, .chat-comment-preview) .btn svg { width: 14px; height: 14px; display: block; }

/* Comment list (the chip's preview) */
.chat-comment-preview {
  z-index: 10000;
  position: fixed;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--popover);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  animation: selection-comment-fade-in .12s var(--ease-out);
}
.chat-comment-preview--editable { padding: 4px; }
.chat-comment-preview__scroll {
  width: min(334px, 100vw - 50px);
  max-height: min(320px, 100dvh - 26px);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  overflow: auto;
}
.chat-comment-preview__list { margin: 0; padding: 0; list-style: none; }
.chat-comment-preview__item { padding-inline-start: 28px; position: relative; }
.chat-comment-preview__item + .chat-comment-preview__item { margin-top: 12px; }
.chat-comment-preview__item::before {
  content: counter(list-item);
  box-sizing: border-box;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  min-width: 20px;
  height: 20px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  place-items: center;
  padding-inline: 3px;
  font-size: 11px;
  display: grid;
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
}
.chat-comment-preview__body { gap: 2px; min-width: 0; display: grid; }
.chat-comment-preview__body .muted { color: var(--muted); }
.chat-comment-preview__item:has(.chat-comment-preview__actions) .chat-comment-preview__body { padding-inline-end: 64px; }
.chat-comment-preview__text { overflow-wrap: anywhere; min-width: 0; overflow: hidden; }
.chat-comment-preview__text--selection { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; }
/* Rows whose passage is in the thread jump to it */
.chat-comment-preview__item--link { cursor: pointer; }
.chat-comment-preview:not(.chat-comment-preview--editable) .chat-comment-preview__item--link { border-radius: var(--radius-md); padding: 4px 6px; padding-inline-start: 34px; }
.chat-comment-preview:not(.chat-comment-preview--editable) .chat-comment-preview__item--link::before { inset-block-start: 4px; inset-inline-start: 6px; }
.chat-comment-preview__item--link:is(:hover, :focus-visible) { background: var(--bg-hover); outline: none; }
.chat-comment-preview__text--comment { white-space: pre-wrap; max-height: 4lh; overflow-y: auto; scrollbar-width: thin; }
.chat-comment-preview__text + .muted { margin-top: 4px; }
.chat-comment-preview__actions { display: flex; gap: 2px; position: absolute; inset-block-start: 0; inset-inline-end: 0; }
.chat-comment-preview--editable .chat-comment-preview__item { border-radius: var(--radius-md); padding: 8px 10px; padding-inline-start: 38px; }
.chat-comment-preview--editable .chat-comment-preview__item::before { inset-block-start: 8px; inset-inline-start: 10px; }
.chat-comment-preview--editable .chat-comment-preview__item + .chat-comment-preview__item { margin-top: 0; }
.chat-comment-preview--editable .chat-comment-preview__item:is(:hover, :focus-within) { background: var(--bg-hover); }
.chat-comment-preview--editable .chat-comment-preview__actions { opacity: .65; inset-block-start: 6px; inset-inline-end: 8px; }
.chat-comment-preview--editable .chat-comment-preview__item:is(:hover, :focus-within) .chat-comment-preview__actions { opacity: 1; }

/* "N comments" chip: composer attachment row and sent messages */
.message-comment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.message-comment-chip:hover { color: var(--text-primary); }
.message-comment-chip:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
.message-comment-chip svg { width: 16px; height: 16px; display: block; flex: none; }
.message-comment-chip__text { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.message-comments { flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* Hovering a passage with an unsent comment */
.messages.comment-hover { cursor: pointer; }
.chat-comment-tooltip {
  position: fixed;
  z-index: 10000;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--popover);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 13px;
  pointer-events: none;
}
.chat-comment-tooltip[hidden] { display: none; }
.chat-comment-tooltip > * { max-width: 300px; } /* the box's own max-width is set inline by placement */
.chat-comment-tooltip__text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; line-clamp: 6; overflow: hidden; }
.chat-comment-tooltip .muted { color: var(--muted); }
.chat-comment-tooltip__passage { margin-bottom: 6px; padding-left: 8px; border-left: 2px solid var(--border); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.chat-comment-tooltip__hint { margin-top: 4px; font-size: 11px; }
.message-comments { display: flex; margin-top: 8px; }
.image-preview-item.comment-chip-item { width: auto; height: auto; align-self: center; border: none; overflow: visible; }
.image-preview-item.comment-chip-item .message-comment-chip { padding-right: 30px; }
.image-preview-item.comment-chip-item--more .message-comment-chip { padding-right: 10px; }
.image-preview-item.comment-chip-item .remove-image { top: 50%; right: 5px; transform: translateY(-50%); }
@media (hover: none) {
  .image-preview-item.comment-chip-item .remove-image { opacity: 1; }
}
/* A comments-only message has no text: no empty bubble under the chip */
.message.user .message-content:empty { display: none; }

/* After jumping from a sent chip: the comment, pinned under its passage, with a way back */
.chat-comment-card {
  position: fixed;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--popover);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 13px;
  animation: selection-comment-fade-in .12s var(--ease-out);
}
.chat-comment-card[hidden] { display: none; }
.chat-comment-card__text { max-width: 360px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden; }
.chat-comment-card__text.muted { color: var(--muted); }
.chat-comment-card__actions { display: flex; align-items: center; gap: 2px; flex: none; }
.chat-comment-card .btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: none; border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--text-primary) 8%, transparent);
  color: var(--text-primary); font: inherit; font-size: 12px; cursor: pointer;
}
.chat-comment-card .btn:hover { background: color-mix(in srgb, var(--text-primary) 14%, transparent); }
.chat-comment-card .btn--ghost { background: transparent; color: var(--muted); }
.chat-comment-card .btn--icon { width: 28px; padding: 0; justify-content: center; }
.chat-comment-card svg { width: 14px; height: 14px; display: block; }

/* "Back to your message" pill on top of the scroll buttons (right-aligned, so they don't move) */
.scroll-nav { align-items: flex-end; }
.scroll-back-pill {
  pointer-events: auto;
  display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-secondary);
  color: var(--text-primary);
  font: inherit; font-size: 12px;
  white-space: nowrap; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  animation: selection-comment-fade-in .12s ease-out;
}
.scroll-back-pill[hidden] { display: none; }
.scroll-back-pill:hover { background: var(--surface-hover); }
.scroll-back-pill svg { width: 14px; height: 14px; flex: none; }
