/* Collaboration Center, @mention autocomplete, and the mention/reply
   styling shared by the sales/debtcollection contextual-comment
   partials — see static/erp/collaboration.js for the behaviour. */

/* ---- @mention autocomplete dropdown (floated to <body>, or to the open
   <dialog> when the field lives in one — see MentionField/PeoplePicker
   _ensureDropdown in collaboration.js) ---- */
.mention-dropdown {
  /* fixed, not absolute: coordinates from getBoundingClientRect() are
     viewport-relative (see caretCoordinates()/PeoplePicker._render in
     collaboration.js), and fixed is what lets this render above an
     open <dialog>'s own overflow:hidden when appended inside it. */
  position: fixed; z-index: var(--z-popover);
  width: min(320px, 90vw); max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--elev-3);
}
.mention-dropdown__item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); cursor: pointer;
}
.mention-dropdown__item:hover, .mention-dropdown__item.is-active { background: var(--surface-hover); }
.mention-dropdown__avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: var(--text-2xs); font-weight: 700;
}
.mention-dropdown__text { min-width: 0; display: flex; flex-direction: column; }
.mention-dropdown__name { font-size: var(--text-sm); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-dropdown__subtitle { font-size: var(--text-xs); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-dropdown__empty { padding: var(--space-3); font-size: var(--text-sm); color: var(--text-subtle); }

/* ---- @mention highlight inside rendered bodies ---- */
.mention {
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand); font-weight: 600; border-radius: 4px; padding: 0 3px;
}

/* ---- deep-link focus flash (notification -> comment/message) ---- */
@keyframes collab-flash {
  0% { background: color-mix(in srgb, var(--brand) 22%, transparent); }
  100% { background: transparent; }
}
.collab-flash { animation: collab-flash 2.2s ease-out; }

/* ---- contextual comment thread (sales/_partials/comments.html etc.) ---- */
.comment__actions { display: flex; gap: var(--space-3); margin-top: var(--space-1); }
.comment__actions button, .comment__actions summary {
  background: none; border: none; padding: 0; cursor: pointer; list-style: none;
  font-size: var(--text-xs); color: var(--text-subtle); font-weight: 600;
}
.comment__actions summary::-webkit-details-marker { display: none; }
.comment__actions button:hover, .comment__actions summary:hover { color: var(--brand); }
.comment--reply { margin-inline-start: var(--space-5); border-inline-start: 2px solid var(--line); padding-inline-start: var(--space-3); }
.comment__reply-form { margin-top: var(--space-2); }
.comment__reply-form textarea, .comment-form textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong, var(--line-strong));
  border-radius: 8px; font-family: inherit; font-size: 13.5px; resize: vertical;
}

/* ---- Collaboration Center ---- */
.collab {
  display: grid; grid-template-columns: 320px 1fr; gap: var(--space-4);
  height: calc(100vh - 220px); min-height: 480px;
}
@media (max-width: 900px) {
  .collab { grid-template-columns: 1fr; height: auto; }
  .collab__thread-pane { min-height: 60vh; }
}
.collab__list-pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  overflow: hidden;
}
.collab__list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line);
}
.collab__list-header h1 { font-size: var(--text-lg); margin: 0; }
.collab__search { padding: var(--space-3) var(--space-4) 0; }
.collab__search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: var(--text-sm); background: var(--surface-sunken);
}
.collab__tabs { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); flex-wrap: wrap; }

.collab-conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.collab-conv-item {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  text-decoration: none; color: inherit; border-bottom: 1px solid var(--line);
}
.collab-conv-item:hover { background: var(--surface-hover); }
.collab-conv-item.is-active { background: var(--surface-sunken); }
.collab-conv-item__body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.collab-conv-item__title { font-size: var(--text-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collab-conv-item__group-tag { font-size: var(--text-2xs); color: var(--text-subtle); font-weight: 500; text-transform: uppercase; }
.collab-conv-item__preview { font-size: var(--text-xs); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collab-conv-item__badge {
  min-width: 20px; height: 20px; border-radius: 10px; background: var(--brand); color: #fff;
  font-size: var(--text-2xs); font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.collab-conv-item__badge--mention { background: var(--danger, #c0392b); }

.collab__thread-pane { min-height: 0; display: flex; flex-direction: column; }
.collab-thread {
  display: flex; flex-direction: column; min-height: 0; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden;
}
.collab-thread--empty { align-items: center; justify-content: center; }
.collab-thread__header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
.collab-thread__title { font-size: var(--text-md); font-weight: 600; }
.collab-thread__meta { font-size: var(--text-xs); color: var(--text-subtle); }
.collab-thread__messages { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }

.collab-msg { display: flex; flex-direction: column; max-width: 72%; align-self: flex-start; }
.collab-msg--mine { align-self: flex-end; align-items: flex-end; }
.collab-msg__reply-ref {
  font-size: var(--text-2xs); color: var(--text-subtle); border-inline-start: 2px solid var(--line);
  padding-inline-start: 6px; margin-bottom: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.collab-msg__bubble {
  background: var(--surface-sunken); border-radius: var(--radius-md); padding: 8px 12px;
  border: 1px solid var(--line);
}
.collab-msg--mine .collab-msg__bubble { background: color-mix(in srgb, var(--brand) 12%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); }
.collab-msg__sender { font-size: var(--text-xs); font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.collab-msg__body { font-size: var(--text-sm); word-break: break-word; white-space: pre-wrap; }

/* ---- attachments + linked-object refs on a sent message ---- */
.collab-msg__attachments { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.collab-msg__attachment {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 5px 9px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  color: var(--text); text-decoration: none; font-size: var(--text-xs); font-weight: 600;
}
.collab-msg__attachment:hover { background: color-mix(in srgb, var(--text) 9%, transparent); }
.collab-msg__attachment .ic { flex-shrink: 0; color: var(--text-subtle); }
.collab-msg__attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collab-msg__refs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.collab-msg__ref {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line));
  color: var(--brand); text-decoration: none; font-size: var(--text-2xs); font-weight: 600;
}
.collab-msg__ref:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.collab-msg__ref .ic { flex-shrink: 0; }

.collab-msg__meta { font-size: var(--text-2xs); color: var(--text-subtle); margin-top: 4px; }
.collab-msg__actions { display: flex; gap: var(--space-2); margin-top: 2px; }
.collab-msg__actions button {
  background: none; border: none; padding: 0; cursor: pointer;
  font-size: var(--text-2xs); color: var(--text-subtle); font-weight: 600;
}
.collab-msg__actions button:hover { color: var(--brand); }
.collab-msg.is-flash .collab-msg__bubble { animation: collab-flash 2.2s ease-out; }
.collab-msg--deleted .collab-msg__body { color: var(--text-disabled); font-style: italic; }

/* ---- composer: a single rounded card (input + toolbar), not a bare
   textarea+button row — attach-file/attach-object live in a toolbar
   strip under the input, alongside send. ---- */
.collab-composer {
  display: flex; flex-direction: column; gap: 6px;
  margin: 0 var(--space-4) var(--space-4); padding: 8px 10px 6px;
  border: 1px solid var(--line-strong, var(--line)); border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.collab-composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
/* The [hidden] attribute's UA-stylesheet `display:none` and this
   class's own `display:flex` are equal specificity — an author rule
   always wins that tie, so without this the reply-preview rendered as
   an empty bar even while hidden. Same fix applies to .collab-
   composer__staged below (also display:flex while shown). */
.collab-composer__reply-preview[hidden],
.collab-composer__staged[hidden] { display: none; }
.collab-composer__reply-preview {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--text-subtle); background: var(--surface-sunken);
  border-radius: var(--radius-sm); padding: 6px 10px; width: 100%;
}
.collab-composer__reply-preview button { background: none; border: none; cursor: pointer; color: var(--text-subtle); }

/* ---- staged attachments/refs: picked but not sent yet ---- */
.collab-composer__staged { display: flex; flex-wrap: wrap; gap: 6px; }
.collab-composer__chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding-block: 4px 4px; padding-inline: 9px 6px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); border: 1px solid var(--line);
  font-size: var(--text-xs); font-weight: 600; color: var(--text);
}
.collab-composer__chip .ic { flex-shrink: 0; color: var(--text-subtle); }
.collab-composer__chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.collab-composer__chip.is-uploading { color: var(--text-subtle); }
.collab-composer__chip.is-error { border-color: var(--danger, #c0392b); color: var(--danger, #c0392b); }
.collab-composer__chip-remove {
  background: none; border: none; cursor: pointer; color: var(--text-subtle);
  font-size: var(--text-sm); line-height: 1; padding: 0 2px; flex-shrink: 0;
}
.collab-composer__chip-remove:hover { color: var(--danger, #c0392b); }

.collab-composer__input {
  resize: none; max-height: 140px; padding: 4px 2px;
  border: none; background: none; font: inherit; font-size: var(--text-sm);
}
.collab-composer__input:focus { outline: none; }

.collab-composer__toolbar { display: flex; align-items: center; gap: 2px; }
.collab-composer__tool {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: none; background: none;
  color: var(--text-subtle); cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.collab-composer__tool:hover, .collab-composer__tool.is-active { background: var(--surface-hover); color: var(--brand); }
.collab-composer__spacer { flex: 1; }
.collab-composer__send {
  width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.collab-composer__send:disabled { opacity: 0.5; cursor: not-allowed; }
.collab-composer.is-sending .collab-composer__send { opacity: 0.6; }
.collab-composer__error { font-size: var(--text-xs); color: var(--danger, #c0392b); padding: 0 var(--space-4) var(--space-2); }

/* ---- "attach a record" popover, opened from the composer toolbar ---- */
.collab-object-picker {
  position: fixed; z-index: var(--z-popover); width: min(320px, 92vw); max-height: 340px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: var(--elev-3);
}
/* Same [hidden]-vs-author-display fix as .collab-composer__reply-preview
   above: this class's own `display: flex` has equal specificity to the
   browser's built-in `[hidden]{display:none}`, and an author rule wins
   that tie — so without this, setting .hidden = true in JS (closeObjectPicker
   in collaboration.js) never actually hid the popover. */
.collab-object-picker[hidden] { display: none; }
.collab-object-picker__search {
  flex-shrink: 0; padding: 8px; border-bottom: 1px solid var(--line);
}
.collab-object-picker__search input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: var(--text-sm); background: var(--surface-sunken);
}
.collab-object-picker__results { overflow-y: auto; padding: var(--space-2); }
.collab-object-picker__group-label {
  font-size: var(--text-2xs); font-weight: 700; text-transform: uppercase; color: var(--text-subtle);
  padding: var(--space-2) var(--space-2) 4px;
}
.collab-object-picker__item {
  display: flex; flex-direction: column; width: 100%; text-align: start;
  padding: 6px var(--space-2); border-radius: var(--radius-sm); border: none; background: none; cursor: pointer;
}
.collab-object-picker__item:hover, .collab-object-picker__item.is-active { background: var(--surface-hover); }
.collab-object-picker__item-label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.collab-object-picker__item-meta { font-size: var(--text-xs); color: var(--text-subtle); }
.collab-object-picker__empty { padding: var(--space-3); font-size: var(--text-sm); color: var(--text-subtle); text-align: center; }

/* ---- Collaboration panel: right-side drawer (erp/_collaboration_panel.html) ----
   Same slide-in mechanism as .erp-help-panel in shell.css: fixed to the
   right edge, toggled by a class on <html> rather than the panel itself,
   with its own full-screen backdrop. Kept as a sibling ruleset here
   rather than merged into .erp-help-panel so each panel's open state is
   independent (a page could reasonably want both trigger buttons without
   one drawer's CSS accidentally reacting to the other's class). */
.erp-collab-panel {
  position: fixed; top: 0; inset-inline-end: 0; bottom: 0; z-index: var(--z-modal);
  width: min(420px, 92vw); display: flex; flex-direction: column;
  background: var(--surface); border-inline-start: 1px solid var(--line); box-shadow: var(--elev-3);
  transform: translateX(100%); transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  /* hidden while closed: its shadow otherwise bleeds into the right edge of every page */
  visibility: hidden;
}
html.collab-open .erp-collab-panel { transform: translateX(0); visibility: visible; transition: transform var(--dur) var(--ease), visibility 0s; }
.erp-collab-backdrop {
  display: none; position: fixed; inset: 0; z-index: var(--z-backdrop);
  background: rgba(13, 33, 29, 0.4); opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
html.collab-open .erp-collab-backdrop { display: block; opacity: 1; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) {
  .erp-collab-panel, .erp-collab-backdrop { transition: none; }
}
.erp-collab-panel__head {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line);
}
.erp-collab-panel__head strong { font-size: var(--text-lg); }
.erp-collab-panel__body { flex: 1; min-height: 0; overflow-y: auto; }
.erp-collab-panel__loading { padding: var(--space-5); text-align: center; color: var(--text-subtle); font-size: var(--text-sm); }
.erp-collab-panel__foot {
  flex-shrink: 0; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line);
}
.erp-collab-panel__foot a { font-size: var(--text-sm); color: var(--brand); text-decoration: none; font-weight: 600; }
.erp-collab-panel__foot a:hover { text-decoration: underline; }

/* The list/thread two-pane grid (.collab above) collapses to the same
   stacked single column the full Collaboration Center already switches
   to under 900px — the panel is narrower than that at every viewport
   size, so it always gets the stacked treatment regardless of the
   window's own width. */
.erp-collab-panel__body .collab { display: block; height: auto; }
.erp-collab-panel__body .collab__list-pane { border-width: 0 0 1px; border-radius: 0; }
.erp-collab-panel__body .collab__thread-pane { min-height: 60vh; }

/* ---- new-conversation dialog: people picker ---- */
.people-picker { display: flex; flex-direction: column; gap: var(--space-2); }
.people-picker__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.people-picker__chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-sunken);
  border: 1px solid var(--line); border-radius: 999px; padding-block: 3px 3px; padding-inline: 10px 6px; font-size: var(--text-xs);
}
.people-picker__chip button { background: none; border: none; cursor: pointer; color: var(--text-subtle); font-size: var(--text-sm); line-height: 1; }
.people-picker__input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: var(--text-sm);
}
