/* ===========================================================================
   Conversation features: reactions, reply, edit, pin, emoji picker
   Loaded on body.cl-app-conversation (and cl-app-chat for pin icon).
   Uses the same CSS variables as master.styles.css.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   0.  position: relative on bubble body so quick-react can float above it
   --------------------------------------------------------------------------- */
body.cl-app-conversation .message-data__body {
    position: relative;
}

.msg-reaction-affordance {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

/* ---------------------------------------------------------------------------
   1.  Reply-to quote block (shown inside the bubble)
   --------------------------------------------------------------------------- */
.msg-reply-quote {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-left: 3px solid var(--cl-primary-color);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    font-size: 12px;
    max-width: 100%;
    overflow: hidden;
}

.msg-reply-quote__sender {
    font-weight: 700;
    color: var(--cl-primary-color);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-reply-quote__body {
    color: var(--cl-secondary-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}

.conversation-messages__item.right .msg-reply-quote {
    border-left-color: var(--cl-primary-color);
    background: rgba(0, 0, 0, 0.06);
}

/* ---------------------------------------------------------------------------
   2.  Quick-react hover bar
   --------------------------------------------------------------------------- */
.msg-quick-react {
    position: absolute;
    bottom: 100%;
    left: 0;
    z-index: 50;
    display: none;
    align-items: center;
    gap: 2px;
    background: var(--cl-primary-bg-color);
    border: 1px solid var(--cl-primary-border-color);
    border-radius: 24px;
    padding: 4px 7px;
    margin-bottom: 2px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    white-space: nowrap;
    pointer-events: auto;
}

.msg-quick-react::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 10px;
}

.msg-reaction-affordance:hover .msg-quick-react,
.msg-reaction-affordance:focus-within .msg-quick-react,
.msg-reaction-affordance.is-open .msg-quick-react {
    display: flex;
}

.conversation-messages__item.right .msg-reaction-affordance .msg-quick-react {
    left: auto;
    right: 0;
}

.msg-quick-react__btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.12s, background 0.12s;
}

.msg-quick-react__btn:hover {
    transform: scale(1.3);
    background: var(--cl-secondary-bg-color);
}

.msg-quick-react__btn.is-mine {
    background: color-mix(in srgb, var(--cl-primary-color) 20%, transparent);
}

.msg-quick-react__btn--more {
    font-size: 14px;
    font-weight: 700;
    color: var(--cl-secondary-text-color);
    width: 26px;
    height: 26px;
}

/* ---------------------------------------------------------------------------
   3.  Reaction chips below the bubble
   --------------------------------------------------------------------------- */
.msg-reaction-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    min-height: 0;
}

.msg-reaction-chips--empty {
    margin-top: 0;
}

.conversation-messages__item.right .msg-reaction-chips { justify-content: flex-end; }
.conversation-messages__item.left  .msg-reaction-chips { justify-content: flex-start; }

.msg-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--cl-secondary-bg-color);
    border: 1px solid var(--cl-primary-border-color);
    border-radius: 12px;
    padding: 2px 8px 2px 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.3;
}

.msg-reaction-chip:hover {
    border-color: var(--cl-primary-color);
    background: color-mix(in srgb, var(--cl-primary-color) 10%, var(--cl-secondary-bg-color));
}

.msg-reaction-chip.is-mine {
    background: color-mix(in srgb, var(--cl-primary-color) 18%, var(--cl-primary-bg-color));
    border-color: color-mix(in srgb, var(--cl-primary-color) 50%, transparent);
}

.msg-reaction-chip__emoji { font-size: 15px; line-height: 1; }
.msg-reaction-chip__count { font-size: 12px; color: var(--cl-secondary-text-color); font-weight: 600; }

/* ---------------------------------------------------------------------------
   4.  Edited badge in message time line
   --------------------------------------------------------------------------- */
.msg-edited-badge {
    font-size: 11px;
    color: var(--cl-secondary-text-color);
    opacity: 0.75;
    margin-left: 5px;
    font-style: italic;
}

/* ---------------------------------------------------------------------------
   5.  Message highlight (after clicking reply quote scroll)
   --------------------------------------------------------------------------- */
@keyframes cl-msg-highlight {
    0%   { background: color-mix(in srgb, var(--cl-primary-color) 22%, transparent); }
    100% { background: transparent; }
}

.conversation-messages__item.msg-highlight .message-data__body > *:first-child {
    animation: cl-msg-highlight 1.4s ease forwards;
    border-radius: var(--cl-primary-border-radius);
}

/* ---------------------------------------------------------------------------
   6.  Pinned message indicator on bubble
   --------------------------------------------------------------------------- */
.conversation-messages__item.is-message-pinned > .message-data > .message-data__body::after {
    content: "📌";
    position: absolute;
    top: -10px;
    font-size: 13px;
    pointer-events: none;
}
.conversation-messages__item.is-message-pinned.left  > .message-data > .message-data__body::after { right: -4px; }
.conversation-messages__item.is-message-pinned.right > .message-data > .message-data__body::after { left: -4px; }

/* ---------------------------------------------------------------------------
   7.  Pinned message strip at top of conversation
   --------------------------------------------------------------------------- */
.msg-pinned-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: color-mix(in srgb, var(--cl-primary-color) 10%, var(--cl-primary-bg-color));
    border-bottom: 1px solid color-mix(in srgb, var(--cl-primary-color) 30%, var(--cl-primary-border-color));
    font-size: 13px;
    cursor: default;
    transition: all 0.2s;
}

.msg-pinned-strip--hidden { display: none !important; }

.msg-pinned-strip__icon { font-size: 16px; flex-shrink: 0; }

.msg-pinned-strip__body { flex: 1; min-width: 0; }

.msg-pinned-strip__label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cl-primary-color);
    margin-bottom: 1px;
}

.msg-pinned-strip__text {
    color: var(--cl-primary-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.msg-pinned-strip__dismiss {
    flex-shrink: 0;
    background: transparent;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: var(--cl-secondary-text-color);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

.msg-pinned-strip__dismiss:hover {
    background: var(--cl-secondary-bg-color);
    color: var(--cl-primary-text-color);
}

/* ---------------------------------------------------------------------------
   8.  Reply / Edit action banners (above the message input)
   --------------------------------------------------------------------------- */
.msg-action-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    background: var(--cl-secondary-bg-color);
    border-top: 1px solid var(--cl-primary-border-color);
    font-size: 13px;
    animation: slideUpBanner 0.18s ease;
}

@keyframes slideUpBanner {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-action-banner__icon {
    font-size: 16px;
    flex-shrink: 0;
    color: var(--cl-primary-color);
}

.msg-action-banner__body { flex: 1; min-width: 0; }

.msg-action-banner__label {
    font-weight: 600;
    color: var(--cl-primary-text-color);
    font-size: 12px;
    margin-bottom: 1px;
}

.msg-action-banner__text {
    color: var(--cl-secondary-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}

.msg-action-banner__dismiss {
    flex-shrink: 0;
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--cl-secondary-text-color);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

.msg-action-banner__dismiss:hover {
    background: var(--cl-primary-border-color);
    color: var(--cl-primary-text-color);
}

/* ---------------------------------------------------------------------------
   9.  Emoji picker (floating, positioned by JS)
   --------------------------------------------------------------------------- */
.cl-emoji-picker {
    position: fixed;
    z-index: 9000;
    background: var(--cl-primary-bg-color);
    border: 1px solid var(--cl-primary-border-color);
    border-radius: var(--cl-secondary-border-radius);
    box-shadow: 0 6px 28px rgba(0,0,0,0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 320px;
}

.cl-emoji-picker[hidden] { display: none !important; }

.cl-emoji-picker:not([hidden]) {
    display: flex;
}

.emoji-picker__chrome {
    padding: 8px 8px 0;
    border-bottom: 1px solid var(--cl-primary-border-color);
    background: var(--cl-secondary-bg-color);
}

.emoji-picker__category-row {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.emoji-picker__category-row::-webkit-scrollbar { display: none; }

.emoji-picker__category-btn {
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 5px 7px;
    cursor: pointer;
    font-size: 17px;
    flex-shrink: 0;
    line-height: 1;
    transition: background 0.13s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
}

.emoji-picker__category-btn:hover { background: var(--cl-primary-border-color); transform: scale(1.1); }
.emoji-picker__category-btn.is-active {
    background: color-mix(in srgb, var(--cl-primary-color) 18%, var(--cl-primary-bg-color));
    color: var(--cl-primary-color);
}

.emoji-picker__search-label {
    display: flex;
    align-items: center;
    padding: 5px 0 7px;
    position: relative;
}

.emoji-picker__search-icon {
    position: absolute;
    left: 8px;
    font-size: 12px;
    pointer-events: none;
    color: var(--cl-secondary-text-color);
}

.emoji-picker__search {
    width: 100%;
    padding: 6px 10px 6px 28px;
    border: 1px solid var(--cl-primary-border-color);
    border-radius: 20px;
    background: var(--cl-primary-bg-color);
    color: var(--cl-primary-text-color);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.emoji-picker__search:focus { border-color: var(--cl-primary-color); }

.emoji-picker__body {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    max-height: 230px;
    scrollbar-width: thin;
    scrollbar-color: var(--cl-primary-border-color) transparent;
}
.emoji-picker__body::-webkit-scrollbar { width: 5px; }
.emoji-picker__body::-webkit-scrollbar-track { background: transparent; }
.emoji-picker__body::-webkit-scrollbar-thumb { background: var(--cl-primary-border-color); border-radius: 4px; }

.emoji-picker__panels { }

.emoji-picker__section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cl-secondary-text-color);
    margin: 5px 2px 4px;
    line-height: 1;
}

.emoji-picker__section-title--muted { opacity: 0.35; }

.emoji-picker__grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1px;
}

.emoji-picker__emoji-btn {
    background: transparent;
    border: none;
    border-radius: 7px;
    padding: 4px 2px;
    cursor: pointer;
    font-size: 19px;
    line-height: 1;
    text-align: center;
    transition: background 0.1s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
}

.emoji-picker__emoji-btn:hover {
    background: var(--cl-secondary-bg-color);
    transform: scale(1.25);
}

.emoji-picker__emoji-btn--search-hide { display: none; }

.emoji-picker__recent-empty {
    font-size: 12px;
    color: var(--cl-secondary-text-color);
    text-align: center;
    padding: 18px 0;
    font-style: italic;
}

.emoji-picker__panel { display: none; }
.emoji-picker__panel.is-active { display: block; }

/* ---------------------------------------------------------------------------
   10. Chat list pin icon (on body.cl-app-chat)
   --------------------------------------------------------------------------- */
.contacts-list__item .chat-pin-icon {
    font-size: 12px;
    opacity: 0.65;
    margin-left: 4px;
    line-height: 1;
    vertical-align: middle;
}

.contacts-list__item .is-chat-pinned-marker {
    display: inline-block;
    font-size: 13px;
    vertical-align: middle;
    margin-right: 4px;
    opacity: 0.7;
}

/* ---------------------------------------------------------------------------
   11. Dark-mode adjustments (mirrors master.styles approach)
   --------------------------------------------------------------------------- */
[data-bg="dark"] .msg-quick-react {
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

[data-bg="dark"] .cl-emoji-picker {
    box-shadow: 0 6px 28px rgba(0,0,0,0.55);
}

[data-bg="dark"] .msg-pinned-strip {
    background: color-mix(in srgb, var(--cl-primary-color) 12%, var(--cl-secondary-bg-color));
}

[data-bg="dark"] .msg-reply-quote {
    background: rgba(255,255,255,0.06);
}
