/* TVClub Chat — interface responsive et présence */

.chat-channel-tabs {
    display: flex;
    background: #111;
    border-bottom: 1px solid #333;
}

.chat-channel-btn {
    flex: 1;
    background: transparent;
    color: #888;
    border: none;
    padding: 0.8rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
}

.chat-channel-btn:hover {
    background: #1a1a1a;
    color: #ccc;
}

.chat-channel-btn.active {
    color: var(--brand-color, #9d4edd);
    border-bottom-color: var(--brand-color, #9d4edd);
}

/* Admin Toast */
.admin-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-toast {
    background-color: #222;
    border-left: 4px solid var(--brand-color, #9d4edd);
    color: #fff;
    padding: 15px 20px;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
    animation: slideInRight 0.3s ease forwards;
    opacity: 0;
    transform: translateX(100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 300px;
}

.admin-toast .close-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1.2rem;
    margin-left: 15px;
}

.admin-toast .close-btn:hover {
    color: #fff;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.admin-toast.hiding {
    animation: fadeOutRight 0.3s ease forwards;
}

/* Chat styles */
.chat-container {
    height: 100%;
    display: flex;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1000px;
    background: #1a1a1a;
    border-radius: 8px;
    border: 1px solid #333;
    overflow: hidden;
    min-width: 0;
}

.chat-header {
    background: #222;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #333;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--brand-color, #9d4edd);
}

.chat-topic-input {
    width: 100%;
    background: transparent;
    border: 1px dashed #555;
    color: var(--brand-color, #9d4edd);
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0.2rem;
    outline: none;
}

.chat-topic-input:focus {
    border-color: var(--brand-color, #9d4edd);
    background: #111;
}

.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-left-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0; /* Important for word-wrap */
}

.chat-sidebar-users {
    width: 250px;
    background: #151515;
    border-left: 1px solid #333;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-sidebar-header {
    font-size: 0.9rem;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.chat-user-row {
    background: #222;
    border-radius: 4px;
    padding: 0.3rem;
}

.chat-user-info, .chat-user-details summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: default;
}

.chat-user-details summary {
    cursor: pointer;
    list-style: none;
}

.chat-user-details summary::-webkit-details-marker {
    display: none;
}

.chat-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-user-name {
    font-size: 0.9rem;
    color: #ccc;
}

.chat-user-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    padding-left: 28px; /* align with text */
}

.chat-user-actions button {
    background: #444;
    border: none;
    color: white;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.chat-user-actions button:hover {
    background: #dc3545;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #111;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.chat-message {
    background: #222;
    padding: 0.8rem;
    border-radius: 6px;
    border-left: 3px solid var(--brand-color, #9d4edd);
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.chat-message-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-message-time {
    color: #888;
    font-size: 0.8rem;
}

.chat-message-content {
    color: #eee;
    word-break: break-word;
}

.chat-admin-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.chat-admin-actions button {
    background: #444;
    border: none;
    color: white;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.chat-admin-actions button:hover {
    background: #dc3545;
}

.chat-input-area {
    display: flex;
    padding: 1rem;
    background: #1a1a1a;
    border-top: 1px solid #333;
    gap: 0.5rem;
}

.chat-emoji-btn {
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    font-size: 1.2rem;
    padding: 0 0.5rem;
    border-radius: 4px;
    cursor: pointer;
}

.chat-input {
    flex: 1;
    background: #2a2a2a;
    border: 1px solid #444;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    outline: none;
}

.chat-input:focus {
    border-color: var(--brand-color, #9d4edd);
}

@media (max-width: 768px) {
    .chat-container {
        padding: 0; /* Enlève le padding sur mobile pour gagner de la place */
    }

    .chat-wrapper {
        border-radius: 0;
        border: none;
    }

    .chat-main {
        flex-direction: column;
    }

    .chat-sidebar-users {
        width: 100%;
        height: 120px; /* Reduced slightly to give chat more room */
        border-left: none;
        border-top: 1px solid #333;
        flex-shrink: 0; /* Ensures it doesn't get squished */
    }

    .chat-message {
        padding: 0.5rem; /* Réduire le padding interne */
    }
}

.chat-send-btn {
    background: var(--brand-gradient, linear-gradient(135deg, #480ca8, #f72585));
    border: none;
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}
/* === Correctif chat dynamique 2026-07-25 === */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.chat-room-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: #111;
    border-bottom: 1px solid #333;
}

.chat-room-select {
    flex: 1;
    min-width: 0;
    color: #eee;
    background: #202020;
    border: 1px solid #444;
    border-radius: 5px;
    padding: 0.55rem 0.75rem;
    font: inherit;
    font-weight: 600;
    outline: none;
}

.chat-room-select:focus {
    border-color: var(--brand-color, #9d4edd);
    box-shadow: 0 0 0 2px rgb(157 78 221 / 20%);
}

.chat-room-select:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.chat-connection-state {
    flex: 0 0 auto;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

.chat-connection-state.is-online { color: #55c878; }
.chat-connection-state.is-connecting { color: #e4b84b; }
.chat-connection-state.is-offline { color: #e26868; }

.chat-load-more {
    text-align: center;
    margin-bottom: 0.2rem;
}

.chat-load-more[hidden] {
    display: none !important;
}

.chat-load-more button,
.chat-retry-btn {
    color: var(--brand-color, #b65cff);
    background: transparent;
    border: 0;
    padding: 0.25rem 0.4rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.chat-load-more button:hover,
.chat-load-more button:focus-visible,
.chat-retry-btn:hover,
.chat-retry-btn:focus-visible {
    text-decoration: underline;
}

.chat-load-more button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-system-status {
    margin: auto;
    color: #999;
    text-align: center;
}

.chat-message-pending {
    opacity: 0.68;
}

.chat-message-status {
    color: #999;
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

.chat-message-name.is-current-user {
    color: var(--brand-color, #b65cff);
}

.chat-message-error {
    color: #ff7b7b;
    border-left-color: #dc3545;
    font-weight: 700;
}

@media (max-width: 600px) {
    .chat-room-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 0.4rem;
    }

    .chat-connection-state {
        align-self: flex-end;
    }
}

/* === Chat v3 : confort utilisateur, non-lus, réponses et réactions === */
.chat-room-toolbar {
    position: relative;
    align-items: center;
}

.chat-room-list {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: thin;
    padding: 0.1rem 0;
}

.chat-room-button {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0.4rem 0.65rem;
    color: #aaa;
    background: #1d1d1d;
    border: 1px solid #383838;
    border-radius: 999px;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
}

.chat-room-button:hover,
.chat-room-button:focus-visible {
    color: #fff;
    border-color: #666;
    outline: none;
}

.chat-room-button.active {
    color: #fff;
    border-color: var(--brand-color, #9d4edd);
    background: rgb(157 78 221 / 18%);
}

.chat-room-button.is-muted .chat-room-button-label::after {
    content: " · silencieux";
    color: #777;
    font-size: 0.72rem;
}

.chat-room-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.chat-room-badge,
.chat-room-mention-badge {
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.28rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #fff;
    background: #555;
    font-size: 0.68rem;
    line-height: 1;
}

.chat-room-mention-badge {
    background: var(--brand-color, #9d4edd);
}

.chat-room-badge[hidden],
.chat-room-mention-badge[hidden] {
    display: none !important;
}

.chat-room-tools {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.55rem;
}

.chat-notification-button {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #eee;
    background: #202020;
    border: 1px solid #444;
    border-radius: 50%;
    cursor: pointer;
}

.chat-notification-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-notification-menu {
    position: absolute;
    top: calc(100% - 0.25rem);
    right: 1rem;
    z-index: 1200;
    width: min(330px, calc(100vw - 2rem));
    padding: 0.45rem;
    color: #eee;
    background: #242424;
    border: 1px solid #4a4a4a;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgb(0 0 0 / 45%);
}

.chat-notification-menu[hidden] {
    display: none !important;
}

.chat-notification-menu > button,
.chat-notification-custom button {
    width: 100%;
    padding: 0.55rem 0.65rem;
    color: #eee;
    background: transparent;
    border: 0;
    border-radius: 5px;
    text-align: left;
    cursor: pointer;
}

.chat-notification-menu > button:hover,
.chat-notification-menu > button:focus-visible,
.chat-notification-custom button:hover,
.chat-notification-custom button:focus-visible {
    background: #353535;
    outline: none;
}

.chat-notification-custom {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4rem;
    margin-top: 0.35rem;
    padding-top: 0.55rem;
    border-top: 1px solid #444;
}

.chat-notification-custom label {
    grid-column: 1 / -1;
    color: #aaa;
    font-size: 0.78rem;
}

.chat-notification-custom input {
    min-width: 0;
    color: #eee;
    background: #151515;
    border: 1px solid #4a4a4a;
    border-radius: 5px;
    padding: 0.45rem;
}

.chat-notification-custom button {
    width: auto;
    background: #353535;
}

.chat-left-col {
    position: relative;
}

.chat-new-messages {
    position: absolute;
    right: 1rem;
    bottom: 82px;
    z-index: 20;
    padding: 0.48rem 0.75rem;
    color: #fff;
    background: #2d2140;
    border: 1px solid var(--brand-color, #9d4edd);
    border-radius: 999px;
    box-shadow: 0 5px 18px rgb(0 0 0 / 40%);
    cursor: pointer;
}

.chat-new-messages[hidden] {
    display: none !important;
}

.chat-unread-separator {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--brand-color, #b65cff);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-unread-separator::before,
.chat-unread-separator::after {
    content: "";
    height: 1px;
    flex: 1;
    background: rgb(182 92 255 / 45%);
}

.chat-message {
    position: relative;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.chat-message:focus-visible {
    outline: 2px solid var(--brand-color, #9d4edd);
    outline-offset: 2px;
}

.chat-message.is-mentioned {
    background: #292033;
    border-left-color: #e9a7ff;
}

.chat-message.is-highlighted {
    background: #3a2b49;
    border-color: #e9a7ff;
}

.chat-message.is-deleted {
    opacity: 0.72;
}

.chat-message.is-deleted .chat-message-content {
    color: #999;
    font-style: italic;
}

.chat-message-edited {
    color: #777;
    font-size: 0.72rem;
}

.chat-message-menu-button {
    margin-left: auto;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 1.25rem;
    line-height: 1;
    opacity: 0;
    cursor: pointer;
}

.chat-message:hover .chat-message-menu-button,
.chat-message:focus-within .chat-message-menu-button,
.chat-message-menu-button[aria-expanded="true"] {
    opacity: 1;
}

.chat-message-menu-button:hover,
.chat-message-menu-button:focus-visible {
    color: #fff;
    background: #3a3a3a;
    outline: none;
}

.chat-message-menu {
    position: absolute;
    top: 2.45rem;
    right: 0.65rem;
    z-index: 100;
    min-width: 170px;
    padding: 0.35rem;
    background: #2a2a2a;
    border: 1px solid #4a4a4a;
    border-radius: 7px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
}

.chat-message-menu[hidden] {
    display: none !important;
}

.chat-message-menu > button {
    width: 100%;
    padding: 0.48rem 0.55rem;
    color: #eee;
    background: transparent;
    border: 0;
    border-radius: 4px;
    text-align: left;
    cursor: pointer;
}

.chat-message-menu > button:hover,
.chat-message-menu > button:focus-visible {
    background: #3b3b3b;
    outline: none;
}

.chat-message-menu > button.is-danger {
    color: #ff8b8b;
}

.chat-message-menu-reactions {
    display: flex;
    gap: 0.15rem;
    padding: 0.25rem 0.15rem 0.4rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid #444;
}

.chat-message-menu-reactions button {
    flex: 1;
    padding: 0.35rem 0.2rem;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

.chat-message-menu-reactions button:hover,
.chat-message-menu-reactions button:focus-visible {
    background: #414141;
    outline: none;
}

.chat-message-reply-preview {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0 0 0.55rem;
    padding: 0.4rem 0.55rem;
    color: #bbb;
    background: #191919;
    border: 0;
    border-left: 2px solid #777;
    border-radius: 3px;
    text-align: left;
    cursor: pointer;
}

.chat-message-reply-preview[hidden] {
    display: none !important;
}

.chat-message-reply-preview strong {
    color: var(--brand-color, #b65cff);
    font-size: 0.78rem;
}

.chat-message-reply-preview span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
}

.chat-mention {
    color: #d79cff;
    font-weight: 700;
}

.chat-mention.is-me {
    color: #fff;
    background: rgb(157 78 221 / 55%);
    border-radius: 3px;
    padding: 0 0.15em;
}

.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.55rem;
}

.chat-reactions:empty {
    display: none;
}

.chat-reaction {
    padding: 0.22rem 0.48rem;
    color: #ddd;
    background: #191919;
    border: 1px solid #404040;
    border-radius: 999px;
    font-size: 0.78rem;
    cursor: pointer;
}

.chat-reaction:hover,
.chat-reaction:focus-visible,
.chat-reaction.is-mine {
    border-color: var(--brand-color, #9d4edd);
    background: rgb(157 78 221 / 18%);
    outline: none;
}

.chat-composer-context {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.5rem 1rem;
    color: #bbb;
    background: #202020;
    border-top: 1px solid #363636;
    border-left: 3px solid var(--brand-color, #9d4edd);
    font-size: 0.8rem;
}

.chat-composer-context[hidden] {
    display: none !important;
}

.chat-composer-context > div {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-composer-context strong {
    color: var(--brand-color, #b65cff);
}

.chat-composer-context span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-composer-context button {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    color: #bbb;
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
}

.chat-composer-context button:hover,
.chat-composer-context button:focus-visible {
    color: #fff;
    background: #3a3a3a;
    outline: none;
}

.chat-input-area {
    align-items: flex-end;
}

.chat-composer-field {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
}

textarea.chat-input {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    line-height: 1.35;
}

.chat-character-counter {
    position: absolute;
    right: 0.55rem;
    bottom: 0.25rem;
    color: #888;
    font-size: 0.66rem;
    pointer-events: none;
}

.chat-character-counter[hidden] {
    display: none !important;
}

.chat-character-counter.is-near-limit {
    color: #ff9b9b;
}

.chat-mention-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 0.35rem);
    z-index: 150;
    max-height: 240px;
    overflow-y: auto;
    padding: 0.35rem;
    background: #252525;
    border: 1px solid #4b4b4b;
    border-radius: 7px;
    box-shadow: 0 8px 25px rgb(0 0 0 / 45%);
}

.chat-mention-suggestions[hidden] {
    display: none !important;
}

.chat-mention-suggestion {
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.5rem;
    color: #eee;
    background: transparent;
    border: 0;
    border-radius: 5px;
    text-align: left;
    cursor: pointer;
}

.chat-mention-suggestion:hover,
.chat-mention-suggestion.active,
.chat-mention-suggestion:focus-visible {
    background: #3a3a3a;
    outline: none;
}

.chat-mention-suggestion img {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-mention-suggestion small {
    color: #63cf83;
    font-size: 0.68rem;
}

.chat-send-btn:disabled,
.chat-emoji-btn:disabled {
    opacity: 0.48;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .chat-room-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.45rem;
    }

    .chat-room-tools {
        justify-content: flex-end;
    }

    .chat-message-menu-button {
        opacity: 1;
    }

    .chat-new-messages {
        bottom: 78px;
    }

    .chat-input-area {
        padding: 0.65rem;
    }
}

/* ------------------------------------------------------------------
   Phase 3 — navigation groupée, responsive, présence et accessibilité
------------------------------------------------------------------ */

#tab-chat {
    min-height: 0;
    overflow: hidden;
}

#tab-chat .chat-container {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: clamp(0.65rem, 1.5vw, 1.25rem);
}

#tab-chat .chat-wrapper {
    position: relative;
    width: min(1180px, 100%);
    height: 100%;
    min-height: 0;
    max-width: 1180px;
    margin: 0 auto;
}

.chat-header {
    flex: 0 0 auto;
}

.chat-room-toolbar {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.65rem;
    flex: 0 0 auto;
    padding: 0.55rem 0.75rem;
}

.chat-room-navigation {
    min-width: 0;
}

.chat-room-list {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    overflow: visible;
    padding: 0;
    scrollbar-width: none;
}

.chat-room-list::-webkit-scrollbar {
    display: none;
}

.chat-room-select {
    display: none;
    width: 100%;
    min-height: 44px;
}

.chat-room-button,
.chat-channel-room-option,
.chat-users-toggle,
.chat-notification-button,
.chat-emoji-btn,
.chat-send-btn,
.chat-message-menu-button,
.chat-users-close,
.chat-new-messages,
.chat-composer-context button {
    min-height: 44px;
    min-width: 44px;
}

.chat-room-button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.32rem;
    height: 44px;
    padding: 0 0.8rem;
    white-space: nowrap;
}

.chat-channel-group {
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
}

.chat-channel-menu-toggle {
    max-width: min(44vw, 300px);
}

.chat-channel-current {
    min-width: 0;
    overflow: hidden;
    color: #cfc3d8;
    font-size: 0.78rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-channel-chevron {
    margin-left: 0.1rem;
    transition: transform 0.16s ease;
}

.chat-channel-menu-toggle[aria-expanded="true"] .chat-channel-chevron {
    transform: rotate(180deg);
}

.chat-channel-menu {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 0;
    z-index: 260;
    display: grid;
    width: min(360px, calc(100vw - 2rem));
    max-height: min(440px, 65vh);
    overflow-y: auto;
    padding: 0.4rem;
    background: #222126;
    border: 1px solid #49424f;
    border-radius: 9px;
    box-shadow: 0 14px 36px rgb(0 0 0 / 55%);
}

.chat-channel-menu[hidden] {
    display: none !important;
}

.chat-channel-room-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.45rem 0.55rem;
    color: #dedde1;
    background: transparent;
    border: 0;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
}

.chat-channel-room-option.has-channel-icon {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
}

.chat-channel-room-option .chat-room-badge,
.chat-channel-room-option .chat-room-mention-badge {
    width: max-content;
    justify-self: end;
}

.chat-channel-room-option:hover,
.chat-channel-room-option:focus-visible,
.chat-channel-room-option.active {
    color: #fff;
    background: rgb(157 78 221 / 22%);
    outline: none;
}

.chat-channel-room-icon {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    object-fit: contain;
    background: #111;
}

.chat-room-meta {
    max-width: 260px;
    overflow: hidden;
    color: #aaa2ad;
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-room-meta[hidden] {
    display: none;
}

.chat-room-tools {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
}

.chat-users-toggle,
.chat-notification-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    color: #ddd;
    background: #29282c;
    border: 1px solid #444047;
    border-radius: 7px;
    padding: 0 0.65rem;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}

.chat-users-toggle:hover,
.chat-users-toggle:focus-visible,
.chat-notification-button:hover,
.chat-notification-button:focus-visible {
    color: #fff;
    border-color: var(--brand-color, #9d4edd);
    outline: 2px solid transparent;
}

.chat-notification-button {
    padding: 0;
}

.chat-connection-state {
    min-width: 68px;
    text-align: right;
}

.chat-main {
    position: relative;
    min-height: 0;
}

.chat-left-col {
    position: relative;
    min-height: 0;
}

.chat-messages {
    min-height: 0;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.chat-system-status {
    display: flex;
    min-height: 100%;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.chat-system-status.is-loading::before {
    content: "";
    width: 18px;
    height: 18px;
    margin-right: 0.65rem;
    border: 2px solid #555;
    border-top-color: var(--brand-color, #9d4edd);
    border-radius: 50%;
    animation: chat-spin 0.8s linear infinite;
}

.chat-system-status.is-error {
    color: #ff9999;
}

@keyframes chat-spin {
    to { transform: rotate(360deg); }
}

.chat-input-area {
    flex: 0 0 auto;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.chat-emoji-btn,
.chat-send-btn {
    flex: 0 0 auto;
}

.chat-message-menu-button {
    width: 44px;
    height: 44px;
    margin-top: -7px;
    margin-bottom: -7px;
}

.chat-message-menu > button,
.chat-message-menu-reactions button,
.chat-mention-suggestion,
.chat-notification-menu > button,
.chat-notification-custom button {
    min-height: 44px;
}

.chat-emoji-picker {
    position: fixed !important;
    z-index: 1200 !important;
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 24px);
}

.chat-sidebar-users {
    position: relative;
    width: clamp(180px, 18vw, 220px);
    padding: 0;
    gap: 0;
    transition: width 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}

.chat-sidebar-titlebar {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.55rem 0.4rem 0.8rem;
    border-bottom: 1px solid #333;
}

.chat-sidebar-titlebar h3 {
    margin: 0;
    color: #aaa;
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.chat-users-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
}

.chat-users-close:hover,
.chat-users-close:focus-visible {
    color: #fff;
    background: #333;
    outline: none;
}

.chat-users-content {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    padding: 0.75rem;
}

.chat-presence-section {
    display: grid;
    gap: 0.42rem;
}

.chat-sidebar-header {
    margin: 0 0 0.15rem;
}

.chat-sidebar-empty {
    padding: 0.45rem 0.2rem;
    color: #777;
    font-size: 0.78rem;
    line-height: 1.35;
}

.chat-user-row {
    min-width: 0;
    padding: 0.38rem;
}

.chat-user-info,
.chat-user-details summary {
    min-width: 0;
    min-height: 36px;
}

.chat-user-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-user-watching {
    margin-left: auto;
    font-size: 0.75rem;
}

.chat-user-watching[hidden] {
    display: none;
}

.chat-users-backdrop {
    display: none;
}

.chat-wrapper.is-sidebar-collapsed .chat-sidebar-users {
    display: none;
}

.chat-wrapper.is-sidebar-collapsed .chat-left-col {
    width: 100%;
}

:where(
    .chat-room-button,
    .chat-channel-room-option,
    .chat-users-toggle,
    .chat-notification-button,
    .chat-message-menu-button,
    .chat-message-menu button,
    .chat-emoji-btn,
    .chat-send-btn,
    .chat-users-close,
    .chat-new-messages,
    .chat-reaction,
    .chat-message-reply-preview,
    .chat-mention-suggestion,
    textarea.chat-input
):focus-visible {
    outline: 2px solid #d291ff;
    outline-offset: 2px;
}

@media (max-width: 1024px) and (min-width: 768px) {
    #tab-chat .chat-container {
        padding: 0.65rem;
    }

    .chat-sidebar-users {
        width: 190px;
    }

    .chat-room-meta {
        display: none;
    }

    .chat-users-toggle span:last-child {
        max-width: 88px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (max-width: 767px) {
    #tab-chat,
    #tab-chat.tab-content.active {
        width: 100%;
        height: var(--chat-available-height, calc(100dvh - 108px));
        min-height: 320px;
        overflow: hidden !important;
    }

    #tab-chat .chat-container {
        height: 100%;
        min-height: 0;
        padding: 0;
    }

    #tab-chat .chat-wrapper {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    .chat-header {
        padding: 0.55rem 0.7rem;
    }

    .chat-header h2,
    .chat-topic-input {
        font-size: 1rem;
    }

    .chat-room-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.45rem;
        padding: 0.45rem 0.55rem;
    }

    .chat-room-navigation {
        min-width: 0;
    }

    .chat-room-list {
        display: none;
    }

    .chat-room-select {
        display: block;
        min-width: 0;
        padding: 0.48rem 2rem 0.48rem 0.65rem;
        color: #eee;
        background: #232326;
        border: 1px solid #454148;
        border-radius: 7px;
        font: inherit;
        font-size: 0.9rem;
        font-weight: 700;
    }

    .chat-room-meta {
        display: none !important;
    }

    .chat-room-tools {
        gap: 0.3rem;
    }

    .chat-users-toggle {
        width: 44px;
        padding: 0;
    }

    .chat-users-toggle span:last-child {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
    }

    .chat-connection-state {
        position: absolute;
        right: 0.55rem;
        bottom: -1.05rem;
        z-index: 2;
        min-width: auto;
        padding: 0.1rem 0.35rem;
        background: #111;
        border-radius: 999px;
        font-size: 0.64rem;
    }

    .chat-main {
        flex: 1;
        min-height: 0;
    }

    .chat-left-col {
        width: 100%;
        min-height: 0;
    }

    .chat-messages {
        padding: 0.65rem;
        gap: 0.6rem;
    }

    .chat-message {
        padding: 0.65rem;
    }

    .chat-message-menu-button {
        opacity: 1;
    }

    .chat-message-menu {
        position: fixed;
        top: auto;
        right: max(0.6rem, env(safe-area-inset-right));
        bottom: max(0.6rem, env(safe-area-inset-bottom));
        left: max(0.6rem, env(safe-area-inset-left));
        width: auto;
        max-height: 70dvh;
        overflow-y: auto;
    }

    .chat-composer-context {
        padding: 0.45rem 0.6rem;
    }

    .chat-input-area {
        position: sticky;
        z-index: 80;
        bottom: 0;
        gap: 0.4rem;
        padding: 0.5rem max(0.55rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.55rem, env(safe-area-inset-left));
        box-shadow: 0 -8px 20px rgb(0 0 0 / 22%);
    }

    textarea.chat-input {
        min-height: 44px;
        max-height: 104px;
        padding: 0.65rem 0.7rem;
    }

    .chat-new-messages {
        right: 0.7rem;
        bottom: calc(70px + env(safe-area-inset-bottom));
        min-height: 44px;
    }

    .chat-sidebar-users {
        position: absolute;
        inset: 0 0 0 auto;
        z-index: 510;
        display: flex;
        width: min(86vw, 340px);
        height: 100%;
        max-height: none;
        border: 0;
        border-left: 1px solid #3b373e;
        box-shadow: -12px 0 32px rgb(0 0 0 / 55%);
        transform: translateX(105%);
        visibility: hidden;
    }

    .chat-wrapper.is-users-drawer-open .chat-sidebar-users {
        transform: translateX(0);
        visibility: visible;
    }

    .chat-users-backdrop {
        position: absolute;
        inset: 0;
        z-index: 500;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgb(0 0 0 / 58%);
        border: 0;
    }

    .chat-users-backdrop[hidden] {
        display: none !important;
    }

    .chat-sidebar-titlebar {
        padding-top: max(0.4rem, env(safe-area-inset-top));
    }

    .chat-notification-menu {
        position: fixed;
        top: auto;
        right: max(0.55rem, env(safe-area-inset-right));
        bottom: max(0.55rem, env(safe-area-inset-bottom));
        left: max(0.55rem, env(safe-area-inset-left));
        width: auto;
        max-height: 75dvh;
        overflow-y: auto;
    }
}

@media (max-width: 375px) {
    .chat-send-btn {
        width: 44px;
        padding: 0;
        overflow: hidden;
        font-size: 0;
    }

    .chat-send-btn::before {
        content: "➤";
        font-size: 1.15rem;
    }

    .chat-emoji-btn {
        padding: 0;
    }

    .chat-room-toolbar {
        padding-inline: 0.4rem;
    }
}

@media (max-width: 330px) {
    .chat-messages {
        padding-inline: 0.45rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .chat-sidebar-users,
    .chat-channel-chevron,
    .admin-toast,
    .chat-new-messages {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }

    .chat-system-status.is-loading::before {
        animation-duration: 1.6s;
    }
}

/* À 768 px exact, les anciennes règles mobiles v3 sont neutralisées. */
@media (width: 768px) {
    #tab-chat .chat-container {
        padding: 0.65rem;
    }

    #tab-chat .chat-wrapper {
        border: 1px solid #333;
        border-radius: 8px;
    }

    .chat-main {
        flex-direction: row;
    }

    .chat-sidebar-users {
        width: 190px;
        height: auto;
        max-height: none;
        border-top: 0;
        border-left: 1px solid #333;
    }
}


/* ------------------------------------------------------------------
   Phase 4 — modération, contexte de chaîne et panneau player
------------------------------------------------------------------ */
.chat-room-banner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .8rem;
    padding: .7rem 1rem;
    background: linear-gradient(110deg, rgb(157 78 221 / 12%), rgb(20 20 20 / 96%));
    border-bottom: 1px solid #343138;
}
.chat-room-banner-logo { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; background:#0d0d0d; }
.chat-room-banner-copy { min-width: 0; }
.chat-room-banner-heading { display:flex; align-items:center; gap:.65rem; flex-wrap:wrap; }
.chat-room-banner-heading strong { color:#f0e8f5; font-size:1rem; }
.chat-room-banner-heading span { color:#aaa; font-size:.76rem; }
.chat-room-banner-description { margin:.18rem 0 0; color:#bdb8c0; font-size:.82rem; line-height:1.35; }
.chat-room-banner-program { display:flex; align-items:baseline; gap:.45rem; margin-top:.38rem; min-width:0; }
.chat-room-banner-program span { color:#999; font-size:.72rem; }
.chat-room-banner-program strong { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#fff; font-size:.84rem; }
.chat-room-banner-actions { display:flex; gap:.4rem; flex-wrap:wrap; justify-content:flex-end; }
.chat-room-banner-actions button,
.chat-pinned-message button,
.chat-user-moderate { min-height:36px; padding:.35rem .65rem; color:#eee; background:#29272c; border:1px solid #4c4651; border-radius:6px; font:inherit; font-size:.76rem; font-weight:700; cursor:pointer; }
.chat-room-banner-actions button:hover,
.chat-room-banner-actions button:focus-visible,
.chat-pinned-message button:hover,
.chat-pinned-message button:focus-visible,
.chat-user-moderate:hover,
.chat-user-moderate:focus-visible { border-color:var(--brand-color,#9d4edd); outline:none; }
.chat-pinned-message { display:flex; align-items:center; gap:.45rem; min-height:38px; padding:.3rem .75rem; background:#211e24; border-bottom:1px solid #38323c; }
.chat-pinned-message[hidden] { display:none!important; }
.chat-pinned-message button { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:left; background:transparent; border-color:transparent; }
.chat-message-content a.chat-message-link { color:#b98cff; text-decoration:underline; overflow-wrap:anywhere; }
.chat-message.is-system { background:rgb(157 78 221 / 10%); border-left-style:dashed; }
.chat-message.is-system .chat-message-name { color:#d5a8ff; }
.chat-message.is-system .chat-message-menu-button { display:none; }
.chat-user-row { display:flex; align-items:center; gap:.35rem; }
.chat-user-info { flex:1; min-width:0; }
.chat-user-moderate { min-height:30px; padding:.2rem .42rem; font-size:.68rem; }

.player-chat-open { position:absolute; left:.75rem; top:.75rem; z-index:34; padding:.48rem .72rem; color:#fff; background:rgb(20 20 20 / 85%); border:1px solid #62566b; border-radius:7px; font:inherit; font-size:.8rem; font-weight:700; cursor:pointer; backdrop-filter:blur(8px); }
.player-container { position:relative; }
.player-chat-panel { display:none; min-width:0; width:min(410px,36vw); background:#111; border-left:1px solid #353238; overflow:hidden; }
.player-chat-panel.is-open { display:flex; flex-direction:column; }
.player-chat-panel-titlebar { display:flex; min-height:46px; align-items:center; justify-content:space-between; padding:.45rem .65rem; background:#1b191d; border-bottom:1px solid #343037; }
.player-chat-panel-titlebar button { width:40px; height:40px; color:#ccc; background:transparent; border:0; border-radius:50%; font-size:1.35rem; cursor:pointer; }
.player-chat-mount { flex:1; min-height:0; }
.player-chat-panel .chat-container { padding:0; height:100%; }
.player-chat-panel .chat-wrapper { max-width:none; border:0; border-radius:0; }
.player-chat-panel .chat-header { display:none; }
.player-chat-panel .chat-room-banner { grid-template-columns:minmax(0,1fr); padding:.55rem .7rem; }
.player-chat-panel .chat-room-banner-logo { display:none; }
.player-chat-panel .chat-room-banner-actions { justify-content:flex-start; }
.player-chat-panel .chat-sidebar-users { display:none; }
.player-chat-panel .chat-users-toggle { display:none; }
.player-chat-panel .chat-room-meta { display:none; }
.player-chat-panel .chat-room-toolbar { grid-template-columns:minmax(0,1fr) auto; }
.player-chat-panel .chat-main { flex:1; }
.player-chat-panel .chat-message { padding:.65rem; }
.player-chat-panel .chat-room-banner-description { max-height:2.7em; overflow:hidden; }
#tab-player .main-content.has-chat-panel { display:grid; grid-template-columns:minmax(0,1fr) minmax(180px,260px) minmax(320px,410px); }

.chat-moderation-modal { position:fixed; inset:0; z-index:2500; display:grid; place-items:center; padding:1rem; }
.chat-moderation-modal[hidden] { display:none!important; }
.chat-moderation-backdrop { position:absolute; inset:0; width:100%; height:100%; border:0; background:rgb(0 0 0 / 72%); cursor:default; }
.chat-moderation-dialog { position:relative; z-index:1; width:min(500px,100%); max-height:calc(100dvh - 2rem); overflow:auto; padding:1rem; color:#eee; background:#211f23; border:1px solid #514b55; border-radius:10px; box-shadow:0 24px 70px rgb(0 0 0 / 65%); }
.chat-moderation-titlebar { display:flex; align-items:center; justify-content:space-between; gap:1rem; }
.chat-moderation-titlebar h3 { margin:0; font-size:1.1rem; }
.chat-moderation-titlebar button { width:40px; height:40px; color:#ccc; background:transparent; border:0; border-radius:50%; font-size:1.4rem; cursor:pointer; }
.chat-moderation-dialog label { display:block; margin:.7rem 0 .3rem; color:#bbb; font-size:.8rem; font-weight:700; }
.chat-moderation-dialog textarea,
.chat-moderation-dialog select,
.chat-moderation-dialog input { box-sizing:border-box; width:100%; min-height:42px; padding:.5rem .65rem; color:#fff; background:#151515; border:1px solid #49434d; border-radius:6px; }
.chat-moderation-actions { display:flex; justify-content:flex-end; gap:.5rem; margin-top:1rem; }
.chat-moderation-actions button { min-height:42px; padding:.45rem .85rem; color:#fff; background:#333038; border:1px solid #57505d; border-radius:6px; cursor:pointer; }
.chat-moderation-actions #chat-moderation-confirm { background:var(--brand-gradient,linear-gradient(135deg,#480ca8,#f72585)); border:0; font-weight:800; }

@media (max-width: 1100px) {
    #tab-player .main-content.has-chat-panel { grid-template-columns:minmax(0,1fr) minmax(300px,390px); }
    #tab-player .main-content.has-chat-panel > .sidebar { display:none; }
}
@media (max-width: 768px) {
    .chat-room-banner { grid-template-columns:auto minmax(0,1fr); padding:.55rem .65rem; }
    .chat-room-banner-logo { width:38px; height:38px; }
    .chat-room-banner-actions { grid-column:1 / -1; justify-content:flex-start; }
    .chat-room-banner-description { max-height:2.8em; overflow:hidden; }
    .player-chat-panel { position:fixed; inset:0; z-index:2200; width:100%; height:100dvh; border:0; }
    .player-chat-panel.is-open { display:flex; }
    .player-chat-panel-titlebar { padding-top:max(.45rem,env(safe-area-inset-top)); }
    .player-chat-panel .chat-container { height:calc(100dvh - 46px - env(safe-area-inset-top)); }
    #tab-player .main-content.has-chat-panel { display:block; }
    #tab-player .main-content.has-chat-panel > .sidebar { display:block; }
    .player-chat-open { min-height:44px; }
}
@media (prefers-reduced-motion: reduce) {
    .player-chat-panel, .chat-moderation-dialog { transition:none!important; animation:none!important; }
}

/* ------------------------------------------------------------------
   Phase 4.1 — polish panneau player, hauteur du chat et menus
------------------------------------------------------------------ */

/* Le mount ajouté en phase 4 doit transmettre la hauteur de l'onglet. */
.chat-home-mount {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.chat-home-mount > .chat-container {
    flex: 1 1 auto;
    min-height: 0;
}

/* Bouton discret : icône seule, mais cible et libellé accessibles. */
.player-chat-open {
    top: .65rem;
    left: .65rem;
    display: inline-flex;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: rgb(255 255 255 / 82%);
    background: rgb(16 16 18 / 58%);
    border: 1px solid rgb(255 255 255 / 18%);
    border-radius: 50%;
    box-shadow: 0 2px 12px rgb(0 0 0 / 28%);
    opacity: .68;
    backdrop-filter: blur(7px);
    transition: opacity .16s ease, background-color .16s ease, transform .16s ease;
}

.player-chat-open:hover,
.player-chat-open:focus-visible,
.player-chat-open[aria-expanded="true"] {
    color: #fff;
    background: rgb(28 25 31 / 88%);
    border-color: rgb(192 127 235 / 58%);
    opacity: 1;
    transform: scale(1.04);
    outline: none;
}

.player-chat-open-label {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
}

/* Le panneau remplace la liste des chaînes au lieu de créer une 3e colonne. */
#tab-player .main-content.has-chat-panel {
    display: flex !important;
    grid-template-columns: none !important;
    min-width: 0;
}

#tab-player .main-content.has-chat-panel > .player-container {
    flex: 1 1 auto;
    min-width: 0;
}

#tab-player .main-content.has-chat-panel > .sidebar {
    display: none !important;
}

.player-chat-panel {
    flex: 0 0 clamp(350px, 31vw, 430px);
    width: clamp(350px, 31vw, 430px);
    min-width: 0;
    overflow: hidden;
}

.player-chat-mount {
    overflow: hidden;
}

/* Dans le volet, conserver le contexte sans sacrifier la conversation. */
.player-chat-panel .chat-room-banner {
    grid-template-columns: minmax(0, 1fr);
    gap: .25rem;
    padding: .45rem .65rem;
}

.player-chat-panel .chat-room-banner-description,
.player-chat-panel .chat-room-banner-actions,
.player-chat-panel .chat-room-banner-logo {
    display: none !important;
}

.player-chat-panel .chat-room-banner-heading {
    display: flex;
    align-items: baseline;
    gap: .45rem;
}

.player-chat-panel .chat-room-banner-program {
    display: flex;
    min-width: 0;
    gap: .35rem;
    overflow: hidden;
    font-size: .75rem;
    white-space: nowrap;
}

.player-chat-panel .chat-room-banner-program[hidden] {
    display: none !important;
}

.player-chat-panel .chat-room-banner-program strong {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Le volet étroit utilise le select natif : compact et toujours scrollable. */
.player-chat-panel .chat-room-list {
    display: none !important;
}

.player-chat-panel .chat-room-select {
    display: block !important;
    min-height: 40px;
    padding: .42rem 2rem .42rem .6rem;
    font-size: .82rem;
}

.player-chat-panel .chat-room-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .4rem;
    padding: .4rem .55rem;
}

.player-chat-panel .chat-room-tools {
    gap: .3rem;
}

.player-chat-panel .chat-notification-button {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
}

.player-chat-panel .chat-connection-state {
    width: 10px;
    min-width: 10px;
    height: 10px;
    overflow: hidden;
    padding: 0;
    border-radius: 50%;
    background: currentColor;
    font-size: 0;
    box-shadow: 0 0 0 3px rgb(255 255 255 / 5%);
}

.player-chat-panel .chat-main,
.player-chat-panel .chat-left-col,
.player-chat-panel .chat-messages {
    min-height: 0;
}

.player-chat-panel .chat-message {
    padding: .58rem .62rem;
}

.player-chat-panel .chat-input-area {
    padding: .48rem .55rem max(.48rem, env(safe-area-inset-bottom));
}

/* Menu placé dans le viewport par chat.js : il ne peut plus être rogné. */
.chat-channel-menu {
    z-index: 2350;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.chat-channel-menu[data-placement="top"] {
    transform-origin: bottom left;
}

.chat-channel-menu[data-placement="bottom"] {
    transform-origin: top left;
}

@media (max-width: 900px) and (min-width: 768px) {
    .player-chat-panel {
        flex-basis: min(390px, 44vw);
        width: min(390px, 44vw);
    }
}

@media (max-width: 767px) {
    .player-chat-open {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        opacity: .78;
    }

    .player-chat-panel {
        width: 100%;
        max-width: none;
        overflow: hidden;
    }

    .player-chat-panel .chat-room-banner-description {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .player-chat-open {
        transition: none !important;
    }
}

@media (max-width: 768px) {
    #tab-player .main-content.has-chat-panel {
        display: block !important;
    }

    #tab-player .main-content.has-chat-panel > .sidebar {
        display: block !important;
    }
}


/* === POLISH 2: bouton chat aligné sur les contrôles du player === */
/* Même gabarit et même apparition au survol que les boutons i/cadenas. */
.player-container > .player-chat-open {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 36;
    display: inline-flex;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 999px;
    border: 1px solid rgba(210, 235, 255, 0.38);
    background: rgba(0, 0, 0, 0.22);
    color: rgba(235, 248, 255, 0.72);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
    opacity: 0;
    transform: scale(0.92);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        background 140ms ease,
        border-color 140ms ease,
        color 140ms ease;
    backdrop-filter: none;
    cursor: pointer;
    pointer-events: auto;
    user-select: none;
}

.player-container > .player-chat-open i {
    display: block;
    font-size: 12px;
    line-height: 1;
}

.player-container > .player-chat-open::after {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 999px;
}

/* Le bouton n'est visible que lorsque le pointeur/focus est dans le lecteur. */
.player-container:hover > .player-chat-open,
.player-container > .player-chat-open:focus-visible {
    opacity: 0.72;
    transform: scale(1);
}

.player-container:hover > .player-chat-open:hover,
.player-container:hover > .player-chat-open[aria-expanded="true"],
.player-container > .player-chat-open:focus-visible {
    opacity: 1;
    background: rgba(0, 0, 0, 0.62);
    border-color: rgba(190, 230, 255, 0.72);
    color: rgba(245, 252, 255, 0.96);
    transform: scale(1);
    outline: none;
}

/* Neutralise l'ancienne règle qui gardait le bouton visible panneau ouvert. */
.player-container:not(:hover) > .player-chat-open[aria-expanded="true"]:not(:focus-visible) {
    opacity: 0;
    transform: scale(0.92);
}

/* Sur un écran tactile sans survol, le contrôle doit rester découvrable. */
@media (hover: none), (pointer: coarse) {
    .player-container > .player-chat-open,
    .player-container > .player-chat-open[aria-expanded="true"] {
        opacity: 0.78;
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .player-container > .player-chat-open {
        transition: none !important;
    }
}
