/* Chat message feed (markup: bubble() in chat-work.js). Loaded after contrast.css.
   - Own messages carry no author line; consecutive messages of one author within 5 minutes
     are grouped (.message.grouped): no repeated avatar or name, tight spacing.
   - All message actions live in one toolbar (.message-quick). On hover devices it floats over
     the top edge of the bubble, so the bubble no longer changes size when the mouse passes. */

:root[data-theme] #app .messenger-shell .messages .message { margin-bottom: var(--sp-3); }
:root[data-theme] #app .messenger-shell .messages .message.grouped { margin-top: calc(var(--sp-3) * -1 + 3px); }
:root[data-theme] #app .messenger-shell .messages .message.grouped > .avatar { visibility: hidden; height: 0; }

:root[data-theme] #app .messenger-shell .bubble { padding: 8px 12px 6px; min-width: 72px; }
:root[data-theme] #app .messenger-shell .bubble-author { display: block; margin-bottom: 2px; }
:root[data-theme] #app .messenger-shell .bubble-author b { margin: 0; font-size: var(--fs-xs); font-weight: 650; }
:root[data-theme] #app .messenger-shell .bubble .message-text { line-height: 1.5; }
:root[data-theme] #app .messenger-shell .bubble .message-reactions:empty { display: none; }
:root[data-theme] #app .messenger-shell .bubble .message-meta { margin-top: 2px; gap: 6px; font-size: var(--fs-2xs); line-height: 1.2; }
:root[data-theme] #app .messenger-shell .bubble .message-meta time { font-variant-numeric: tabular-nums; }

/* Grouped bubbles: soften the corner that points to the previous message */
:root[data-theme] #app .messenger-shell .message.grouped:not(.own) .bubble { border-top-left-radius: var(--r-md); }
:root[data-theme] #app .messenger-shell .message.grouped.own .bubble { border-top-right-radius: var(--r-md); }

/* ---------- Action toolbar ---------- */
:root[data-theme] #app .messenger-shell .message-quick .quick-action {
  min-width: 28px; min-height: 28px; padding: 2px 6px; justify-content: center;
  border-color: transparent; background: transparent; color: var(--ink); font-size: var(--fs-md); line-height: 1;
}
:root[data-theme] #app .messenger-shell .message-quick .quick-action:hover,
:root[data-theme] #app .messenger-shell .message-quick .quick-action[aria-pressed="true"] {
  background: var(--blue-soft); border-color: var(--blue-line); color: var(--ink);
}
:root[data-theme] #app .messenger-shell .message-quick .quick-action > .icon { width: 18px; height: 18px; color: var(--ink); opacity: 1; }
:root[data-theme] #app .messenger-shell .message-quick .quick-action > .icon[data-icon="more"] { stroke-width: 3; }

@media (hover: hover) and (min-width: 761px) {
  :root[data-theme] #app .messenger-shell .message-quick {
    position: absolute; top: -18px; right: 8px; z-index: 4; margin: 0; flex-wrap: nowrap; gap: 2px; padding: 2px;
    border: 1px solid var(--control-line); border-radius: var(--r-md); background: var(--surface);
    box-shadow: 0 4px 14px var(--shadow-strong, rgb(16 24 40 / .16));
  }
  :root[data-theme] #app .messenger-shell .own .message-quick { right: auto; left: 8px; }
  /* Icon-only «Переслать» in the floating toolbar (the title still says it) */
  :root[data-theme] #app .messenger-shell .message-quick .quick-action > span { display: none; }
  /* Emoji picker opens under the toolbar */
  :root[data-theme] #app .messenger-shell .message-quick:has(.quick-reactions) { flex-wrap: wrap; width: 232px; }
}

/* Touch: the toolbar opens under the text after a tap on the bubble */
@media (hover: none), (max-width: 760px) {
  :root[data-theme] #app .messenger-shell .bubble.show-actions .message-quick {
    margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); gap: 4px;
  }
}

/* ---------- Time on the last line of the text ----------
   The time (+ ticks) floats into the free end of the last line, so a short message is one line high
   instead of text + a separate time row. Long lines push it to its own line. */
:root[data-theme] #app .messenger-shell .bubble { display: flow-root; }
:root[data-theme] #app .messenger-shell .bubble > .message-text { display: inline; }
:root[data-theme] #app .messenger-shell .bubble > .message-meta {
  float: right; position: relative; top: 5px; margin: 0 0 0 12px; line-height: 21px;
}

/* ---------- Composer: one frame that never jumps ----------
   Row 1: the text (grows with the text up to ~8 lines, then scrolls).
   Row 2: tools · hint / «… печатает» / send status · «Позже» · send.
   The hint lives in the free middle of the tool row, so focusing or typing never changes the height. */
:root #app .messenger-shell .messenger-composer { padding: 0; }
:root #app .messenger-shell .message-form,
:root #app .messenger-shell .message-form:hover,
:root #app .messenger-shell .message-form:focus-within {
  grid-template-columns: auto minmax(0, 1fr) auto 40px; grid-template-rows: auto 40px; padding: 10px 12px 10px 14px;
}
:root #app .messenger-shell .message-form > .message-tools { grid-column: 1; grid-row: 2; }
:root #app .messenger-shell .message-form > .composer-help,
:root #app .messenger-shell .message-form > .send-status { grid-column: 2; grid-row: 2; min-width: 0; padding: 0 4px; }
:root #app .messenger-shell .message-form > .send-status { position: static; height: 24px; }
:root #app .messenger-shell .message-form > [data-work=schedule] { grid-column: 3; grid-row: 2; }
:root #app .messenger-shell .message-form > button[type=submit] { grid-column: 4; grid-row: 2; }
:root #app .messenger-shell .message-form .composer-help { justify-content: flex-start; color: var(--muted); }
/* the keyboard hint only while writing; «… печатает» / «В чате: N» stays */
:root #app .messenger-shell .messenger-composer:not(:focus-within) .composer-help > span:first-child { visibility: hidden; }
:root #app .messenger-shell .message-form .composer-help #chat-presence:not(:empty) { color: var(--secondary); }
:root #app .messenger-shell .message-form .composer-help:has(#chat-presence:not(:empty)) > span:first-child { display: none; }
:root #app .messenger-shell .message-form .composer-help #chat-presence { margin-left: 0; }

:root #app .messenger-shell .message-input textarea {
  field-sizing: content; height: auto; min-height: 52px; max-height: 208px; padding: 2px; line-height: 24px;
}
@media (max-width: 760px) {
  :root #app .messenger-shell .message-form,
  :root #app .messenger-shell .message-form:focus-within { padding: 8px 8px 8px 10px; gap: 4px 6px; }
  /* the phone shows «… печатает» only; the keyboard hint is for desktop */
  :root #app .messenger-shell .message-form .composer-help > span:first-child { display: none; }
  :root #app .messenger-shell .message-input textarea { max-height: 144px; }
}
:root[data-keyboard-open] #app .messenger-shell .message-input textarea { height: auto; min-height: 48px; max-height: 120px; }

/* ---------- A message on its way: shown at once, a small clock instead of the ticks ---------- */
:root[data-theme] #app .messenger-shell .message.is-sending .message-quick { display: none !important; }
:root[data-theme] #app .messenger-shell .message-sending { display: inline-flex; align-items: center; color: var(--muted); }
:root[data-theme] #app .messenger-shell .message-sending .icon { width: 13px; height: 13px; }
