﻿/* ===============================
   Chat – Variablen & Layout
   =============================== */
:root {
    --chat-height: min(80vh, 500px);
    --chat-spacing-vertical: 0.25rem;
    --chat-bubble-radius: 1rem;
    --chat-bubble-self-bg: #e9f1ff;
    --chat-bubble-other-bg: #ffffff;
    --chat-bubble-shadow: 0 1px 2px rgba(0,0,0,0.1);
    --chat-animation-duration: 200ms;
}

/* Chat-Container-Höhensteuerung innerhalb einer Card */
#chat-section .card-body {
    display: flex;
    flex-direction: column;
    height: var(--chat-height);
}

    /* Flex-Aufteilung für die Chat-Spalten */
    #chat-section .card-body > .row.flex-grow-1 {
        display: flex;
        flex: 1 1 auto;
        overflow: hidden;
        margin: 0;
        min-height: 0;
    }

        #chat-section .card-body > .row.flex-grow-1 > .col-sm-3,
        #chat-section .card-body > .row.flex-grow-1 > .col-sm-9,
        #chat-section .card-body > .row.flex-grow-1 > .col-12 {
            display: flex;
            flex-direction: column;
            min-height: 0;
        }

/* Kanal-Liste (Scroll) */
#chat-channels {
    flex: 1 1 auto;
    overflow-y: auto;
}

    #chat-channels li.list-group-item.online {
        position: relative;
    }

        #chat-channels li.list-group-item.online::before {
            content: "";
            position: absolute;
            top: 8px;
            left: 12px;
            width: 10px;
            height: 10px;
            background-color: #39FF14;
            border: 2px solid #39FF14;
            border-radius: 50%;
            box-sizing: border-box;
            pointer-events: none;
        }

/* Chats (Scroll) */
#chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
}

/* Kanal-Header & -Items (Button-Look) */
#chat-channel-header .list-group-item,
#chat-channels .list-group-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: .25rem .5rem;
    font-size: .875rem;
    line-height: 1.5;
    border: 1px solid var(--bs-primary);
    border-radius: .2rem;
    background-color: transparent;
    color: var(--bs-primary);
    margin-bottom: .25rem;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}

    #chat-channel-header .list-group-item:hover,
    #chat-channels .list-group-item:hover {
        background-color: rgba(var(--bs-primary-rgb), .1);
    }

    #chat-channel-header .list-group-item.active,
    #chat-channels .list-group-item.active {
        background-color: var(--bs-primary);
        border-color: var(--bs-primary);
        color: #fff;
    }

/* Online-Buddies Panel */
#onlineBuddiesList {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
}

/* ===============================
   Bubbles & Reihen
   =============================== */

/* Responsive Tabellen-/Stacked-Ansicht für Chat-Zeilen */
#chat-messages .chat-row--table {
    display: none;
    align-items: center;
    grid-template-columns: auto 1fr auto;
    gap: 0.5rem;
}

#chat-messages .chat-row--stacked {
    display: block;
}

@media (min-width: 576px) {
    #chat-messages .chat-row--table {
        display: grid;
    }

    #chat-messages .chat-row--stacked {
        display: none;
    }
}

/* Bubble-Grundlayout */
#chat-messages .chat-bubble {
    margin: var(--chat-spacing-vertical) 0;
    padding: 0.5rem 0.75rem;
    border-radius: var(--chat-bubble-radius);
    box-shadow: var(--chat-bubble-shadow);
    max-width: 75%;
    position: relative;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--chat-animation-duration) ease-out, transform var(--chat-animation-duration) ease-out;
}

    #chat-messages .chat-bubble.visible {
        opacity: 1;
        transform: translateY(0);
    }

    #chat-messages .chat-bubble.self {
        margin-left: auto;
        background-color: var(--chat-bubble-self-bg);
    }

    #chat-messages .chat-bubble.other {
        margin-right: auto;
        background-color: var(--chat-bubble-other-bg);
    }

    /* Public-Bubble: Layoutsteuerung */
    #chat-messages .chat-bubble.public {
        display: flex;
        align-items: flex-start;
        background-color: var(--chat-bubble-self-bg);
        border-radius: var(--chat-bubble-radius);
        padding: 0.5rem 1rem;
        margin-bottom: 0.5rem;
        max-width: 100%;
        word-break: break-word;
    }

        #chat-messages .chat-bubble.public .avatar {
            width: 24px;
            height: 24px;
            border-radius: 25%;
            margin-right: 0.5rem;
            flex-shrink: 0;
        }

        #chat-messages .chat-bubble.public .content {
            display: flex;
            align-items: baseline;
            flex-wrap: wrap;
            gap: var(--chat-spacing-vertical);
            flex-grow: 1;
        }

        #chat-messages .chat-bubble.public .username-text {
            font-weight: 600;
            color: #004085;
            white-space: nowrap;
        }

        #chat-messages .chat-bubble.public .message-text .grouped-message {
            margin-top: var(--chat-spacing-vertical);
        }

        /* Feinlayout: exakt zwei Flex-Items (Text links | Meta rechts) */
        #chat-messages .chat-bubble.public .content {
            display: block;
            width: 100%;
        }

        #chat-messages .chat-bubble.public .text-part {
            display: flex;
            flex-wrap: wrap;
            align-items: baseline;
            gap: .5rem;
            width: 100%;
            min-width: 0;
        }

        #chat-messages .chat-bubble.public .line-text {
            flex: 1 1 0;
            min-width: 0;
            display: inline;
            overflow-wrap: anywhere;
        }

            #chat-messages .chat-bubble.public .line-text .username-text {
                font-weight: 600;
                color: #004085;
                white-space: nowrap;
                display: inline;
            }

            #chat-messages .chat-bubble.public .line-text .message-text {
                display: inline;
            }

        /* Gruppierte Folgezeilen */
        #chat-messages .chat-bubble.public .message-text .grouped-message {
            display: block;
            margin-top: var(--chat-spacing-vertical);
        }

        /* Meta rechts im Flow */
        #chat-messages .chat-bubble.public .bubble-meta {
            flex: 0 0 auto;
            margin-left: auto;
            display: inline-flex;
            align-items: center;
            gap: .5rem;
            white-space: nowrap;
        }

/* Public-Systemmeldungen (sender-id="0") ent-bubble’n */
.chat-bubble.public[data-sender-id="0"] {
    background: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    text-align: center;
}

    .chat-bubble.public[data-sender-id="0"] .avatar,
    .chat-bubble.public[data-sender-id="0"] .username-text,
    .chat-bubble.public[data-sender-id="0"] .bubble-meta {
        display: none !important;
    }

    .chat-bubble.public[data-sender-id="0"] .message-text {
        display: block;
        margin: 0 auto;
    }

/* Mod-Welcome-Special */
.chat-bubble[data-id="mod-welcome"] {
    background: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 1rem 0 !important;
    text-align: center;
}

    .chat-bubble[data-id="mod-welcome"] .avatar,
    .chat-bubble[data-id="mod-welcome"] .username-text,
    .chat-bubble[data-id="mod-welcome"] .bubble-meta {
        display: none !important;
    }

    .chat-bubble[data-id="mod-welcome"] .message-text {
        display: block !important;
        margin: 0 auto;
        max-width: 80%;
        font-style: italic;
        color: var(--bs-secondary);
    }

/* Private Bubbles im Public-Layout */
#chat-messages .chat-bubble.private-inline .content {
    display: block;
    width: 100%;
}

#chat-messages .chat-bubble.private-inline .text-part {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .5rem;
    width: 100%;
    min-width: 0;
}

#chat-messages .chat-bubble.private-inline .line-text {
    flex: 1 1 0;
    min-width: 0;
    display: inline;
    overflow-wrap: anywhere;
}

#chat-messages .chat-bubble.private-inline .message-text {
    display: inline;
}

    #chat-messages .chat-bubble.private-inline .message-text .grouped-message {
        display: block;
        margin-top: var(--chat-spacing-vertical);
    }

/* Meta (Zeit / Delete) */
#chat-messages .chat-bubble .bubble-meta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

    #chat-messages .chat-bubble .bubble-meta .time {
        font-size: 0.75rem;
        color: #6c757d;
        user-select: none;
        white-space: nowrap;
        flex-shrink: 0;
    }
/* Nicht-public: Meta absolut in der Ecke */
#chat-messages .chat-bubble:not(.public) .bubble-meta {
    position: absolute !important;
    bottom: 0.5rem;
    right: 0.75rem;
}

/* Delete-Buttons Sichtbarkeit */
#chat-messages .chat-bubble .bubble-meta .delete-btn {
    display: none;
    cursor: pointer;
    font-size: 0.8em;
    line-height: 1;
}

@media (hover: none) and (pointer: coarse) {
    #chat-messages .chat-bubble .bubble-meta .delete-btn {
        display: inline-block;
    }
}

@media (hover: hover) {
    #chat-messages .chat-bubble:hover .bubble-meta .delete-btn {
        display: inline-block;
    }
}

.grouped-message .delete-btn {
    cursor: pointer;
    font-size: 0.8em;
    line-height: 1;
    display: none;
    margin-left: 0.25rem;
    color: #999;
    vertical-align: middle;
}

@media (hover: none) and (pointer: coarse) {
    .grouped-message .delete-btn {
        display: inline-block;
    }
}

@media (hover: hover) {
    .grouped-message:hover .delete-btn {
        display: inline-block;
    }
}

/* Inline-Paragraphen in Public-Zeile */
#chat-messages .chat-bubble.public .line-text .message-text p {
    display: inline;
    margin: 0;
}

    #chat-messages .chat-bubble.public .line-text .message-text p + p::before {
        content: " ";
    }

    #chat-messages .chat-bubble.public .line-text .message-text p:empty {
        display: none;
    }

/* Nicht-Public: unmittelbare Kinder inline, grouped bleibt block */
#chat-messages .chat-bubble:not(.public) .message-text > p,
#chat-messages .chat-bubble:not(.public) .message-text > div:not(.grouped-message) {
    display: inline;
    margin: 0;
}

#chat-messages .chat-bubble:not(.public) .message-text .grouped-message {
    display: block;
    margin-top: var(--chat-spacing-vertical);
}

    #chat-messages .chat-bubble:not(.public) .message-text .grouped-message > p,
    #chat-messages .chat-bubble:not(.public) .message-text .grouped-message > div {
        display: inline;
        margin: 0;
    }
/* Platz für absolut positionierte Meta */
#chat-messages .chat-bubble:not(.public) .message-text {
    padding-right: 3.25rem;
    overflow-wrap: anywhere;
}

/* ===============================
   Input, Emoji, Mobile Unread
   =============================== */
#chat-input-row {
    align-items: flex-end;
}

#chat-input {
    height: auto;
    max-height: 6rem;
    overflow-y: auto;
}

.emoji {
    vertical-align: middle;
}

#emoji-panel {
    max-width: 90vw;
    max-height: 50vh;
    overflow-y: auto;
}

    #emoji-panel span {
        display: inline-block;
        margin: 4px;
        cursor: pointer;
    }

/* Mobile Unread Indicator */
.js-mobile-channel-wrapper .mobile-unread-dot {
    position: absolute;
    top: 6px;
    right: 10px;
    width: 16px;
    height: 16px;
    background-color: #dc3545;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(220,53,69,0.6);
    animation: pulseUnread 1.5s infinite ease-in-out;
    display: none;
}

@keyframes pulseUnread {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===============================
   Chat-spezifische Form/Select2
   =============================== */
#chat-section .select2-container--default .select2-selection--single {
    height: 36px;
}

    #chat-section .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 36px;
    }

    #chat-section .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 36px;
    }

    #chat-section .select2-container--default .select2-selection--single .select2-selection__rendered img {
        vertical-align: middle;
    }

/* Kanal-Badge rechts positionieren */
#chat-channels .list-group-item {
    position: relative;
}

    #chat-channel-header .list-group-item .badge,
    #chat-channels .list-group-item .badge {
        position: absolute;
        top: 50%;
        right: 0.25rem;
        transform: translateY(-50%);
    }
