/* =========================================================================
 * Chat-Erweiterungen: Antworten (Reply) + Reactions.
 * Nutzt dieselben Design-Tokens wie desktop.css/mobile.css.
 * ========================================================================= */

/* ---------- Reply-Zitat innerhalb einer Nachricht ---------- */
.msg-reply-quote {
    display: block;
    margin: 0 0 4px 0;
    padding: 4px 8px;
    border-left: 3px solid var(--accent);
    background: var(--surface-2);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.35;
    cursor: pointer;
    max-width: 100%;
    box-sizing: border-box;
}
.msg-reply-quote:hover { background: var(--surface-hover); }
.msg-reply-quote .reply-name {
    display: block;
    font-weight: 700;
    color: var(--accent);
}
.msg-reply-quote .reply-text {
    display: block;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Kurzes Aufblitzen beim Zu-Nachricht-Springen ---------- */
.msg.msg-highlight {
    animation: msg-highlight-flash 1.5s ease;
}
@keyframes msg-highlight-flash {
    0%   { background: var(--accent-soft); }
    100% { background: transparent; }
}

/* ---------- Reactions unter der Nachricht ---------- */
.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 3px;
}
.msg-reactions:empty { display: none; margin: 0; }
.reaction-pill {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 12px;
    line-height: 1.6;
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease;
}
.reaction-pill:hover { background: var(--surface-hover); }
.reaction-pill.mine {
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ---------- Reply-Preview-Bar ueber dem Eingabefeld ---------- */
.reply-preview {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px 0;
    padding: 6px 10px;
    border-left: 3px solid var(--accent);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.reply-preview-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.reply-preview-name {
    font-weight: 700;
    color: var(--accent);
}
.reply-preview-text {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-preview-close {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}
.reply-preview-close:hover { color: var(--text); }

/* ---------- Bild-Anhang-Vorschau ueber dem Eingabefeld ---------- */
.chat-attach-preview {
    display: none;
    align-items: flex-start;
    margin: 0 0 8px 0;
    width: fit-content;
    position: relative;
}
.chat-attach-thumb {
    display: block;
    max-height: 90px;
    max-width: 160px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    object-fit: cover;
}
.chat-attach-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.chat-attach-remove:hover { filter: brightness(1.1); }

/* ---------- Bildanhang innerhalb einer gesendeten Nachricht ---------- */
.msg-image-wrap {
    display: block;
    margin-top: 4px;
}
.msg-image {
    display: block;
    max-width: 240px;
    max-height: 240px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: zoom-in;
    object-fit: cover;
}

/* ---------- Videoanhang innerhalb einer gesendeten Nachricht ---------- */
.msg-video-wrap {
    display: block;
    margin-top: 4px;
}
.msg-video {
    display: block;
    width: 100%;
    max-height: 320px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #000;
}

/* ---------- Bild-Vollbild-Overlay (In-Page, kein neuer Tab) ---------- */
.chat-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100020;
    padding: 40px;
    box-sizing: border-box;
    cursor: zoom-out;
}
.chat-lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    object-fit: contain;
    cursor: default;
}
.chat-lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}
.chat-lightbox-close:hover { background: rgba(255, 255, 255, 0.28); }

/* ---------- Popover-Backdrop (Kontextmenu, Reaction-Picker) ---------- */
.chat-popover-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 100010;
}

/* ---------- Kontextmenu (Rechtsklick / Longtap) ---------- */
.chat-ctx-menu {
    position: fixed;
    z-index: 100011;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 4px;
    min-width: 160px;
}
.chat-ctx-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.chat-ctx-menu-item:hover { background: var(--surface-2); }
.chat-ctx-menu-item.chat-ctx-menu-danger { color: var(--danger); }
.chat-ctx-menu-item.chat-ctx-menu-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* ---------- Geloeschte Nachricht (Tombstone, siehe deleteMessage.php) ---------- */
.msg.msg-deleted { cursor: default; }
.msg.msg-deleted:hover { background: transparent; }
.msg-deleted-text {
    color: var(--text-muted);
    font-style: italic;
}

/* ---------- "Chatarchiv anzeigen" (account.php "Mein Stream"): geloeschte
   Nachricht mit echtem Inhalt statt Platzhalter, nur fuer den Raumbesitzer
   mit aktiver Praeferenz, siehe pollChat.php/renderMessageHtml(). Roter Rand
   als klare optische Markierung "das ist eigentlich geloescht". ---------- */
.msg.msg-archived {
    border: 1px solid var(--danger);
    border-radius: 6px;
    padding: 4px 6px;
    cursor: default;
}
.msg.msg-archived:hover { background: transparent; }

/* ---------- "(bearbeitet)"-Hinweis (editMessage.php, 5-Minuten-Fenster) ---------- */
.msg-edited-tag {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

/* ---------- Reaction-Popover (Quick-Bar + volle Emoji-Auswahl) ---------- */
.chat-reaction-popover {
    position: fixed;
    z-index: 100011;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
}

.reaction-quickbar {
    display: flex;
    align-items: center;
    gap: 2px;
}
.reaction-quickbar button {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color .12s ease, transform .12s ease;
}
.reaction-quickbar button:hover {
    background: var(--surface-2);
    transform: scale(1.15);
}
.reaction-quickbar button.more {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-muted);
}

.emoji-picker {
    width: 260px;
    max-width: 80vw;
}
.emoji-picker-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin-bottom: 4px;
}
.emoji-picker-tabs button {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 17px;
    padding: 5px 0;
    border-radius: 6px;
    cursor: pointer;
    opacity: .55;
}
.emoji-picker-tabs button:hover { background: var(--surface-2); opacity: 1; }
.emoji-picker-tabs button.active { opacity: 1; background: var(--accent-soft); }
.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
}
.emoji-picker-grid button {
    border: none;
    background: transparent;
    font-size: 19px;
    line-height: 1;
    padding: 5px 0;
    border-radius: 6px;
    cursor: pointer;
}
.emoji-picker-grid button:hover { background: var(--surface-2); }

@media (max-width: 960px) {
    /* Mobile: kein natives Text-Callout-Menu/Selection-Popup beim Longtap,
       damit der Longtap zuverlaessig unser Kontextmenu oeffnet statt der
       Browser-eigenen Textauswahl. */
    .msg {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    .emoji-picker { width: 78vw; }
    .emoji-picker-grid { grid-template-columns: repeat(6, 1fr); }
}
