/* ============================================================
   Module Chat interne — widget flottant premium
   Palette : variables CECF injectées par ThemeService (identique à l'AppBar)
   ============================================================ */

.chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: linear-gradient(135deg, var(--kz-primary-dark, #1F6B0A) 0%, var(--kz-primary, #3D9E0F) 100%);
    box-shadow: 0 8px 28px rgba(0,0,0,0.32);
    transition: transform 0.2s ease;
}

.chat-fab:hover {
    transform: scale(1.07);
}

.chat-fab-pulse::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--kz-secondary, #D6C451);
    animation: chat-pulse-ring 2.2s ease-out infinite;
}

@keyframes chat-pulse-ring {
    0%   { transform: scale(0.92); opacity: 0.65; }
    70%  { transform: scale(1.28); opacity: 0; }
    100% { transform: scale(1.28); opacity: 0; }
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    background: var(--kz-secondary, #D6C451);
    color: var(--kz-sidebar-bg, #0D1B12);
    font-size: 11px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    animation: chat-badge-pop 0.28s ease-out;
}

@keyframes chat-badge-pop {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.18); }
    100% { transform: scale(1); }
}

.chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(13,27,18,0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 1998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.chat-backdrop-open {
    opacity: 1;
    pointer-events: auto;
}

.chat-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    width: min(760px, 94vw);
    height: min(680px, 88vh);
    border-radius: 18px;
    background: #f0f4f8;
    box-shadow: 0 24px 64px rgba(0,0,0,0.38);
    z-index: 1999;
    overflow: hidden;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
    pointer-events: none;
    transition: opacity 0.22s cubic-bezier(0.16,1,0.3,1), transform 0.22s cubic-bezier(0.16,1,0.3,1);
}

.chat-panel-open {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

.chat-panel-inner {
    display: flex;
    width: 200%;
    height: 100%;
    transition: transform 0.26s cubic-bezier(0.16,1,0.3,1);
}

.chat-panel-slide {
    transform: translateX(-50%);
}

.chat-pane {
    width: 50%;
    height: 100%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

/* ── Liste des conversations ─────────────────────────────── */

.chat-list-header {
    background: linear-gradient(135deg, var(--kz-primary-dark, #1F6B0A) 0%, var(--kz-primary, #3D9E0F) 100%);
    color: #fff;
    font-weight: 800;
    font-size: 15px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-list-body {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-list-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(13,27,110,0.08);
    background: #fff;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    color: var(--kz-sidebar-bg, #0D1B12);
    background: linear-gradient(135deg, var(--kz-secondary, #D6C451), var(--kz-secondary-dark, #B29A26));
}

.chat-avatar-sm {
    width: 30px;
    height: 30px;
    font-size: 11px;
}

.chat-list-item-text {
    flex: 1;
    min-width: 0;
}

.chat-list-item-title {
    font-weight: 700;
    font-size: 13.5px;
    color: #17233d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-preview {
    font-size: 12px;
    color: #6b7a99;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-unread-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--kz-primary, #3D9E0F);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 20px;
    color: #6b7a99;
    text-align: center;
}

/* ── Fenêtre de conversation ─────────────────────────────── */

.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-window-header {
    background: linear-gradient(135deg, var(--kz-primary-dark, #1F6B0A) 0%, var(--kz-primary, #3D9E0F) 100%);
    color: #fff;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-window-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    overflow: hidden;
}

.chat-window-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Sous-en-tête : filtres (messages/audios/fichiers) + membres ── */

.chat-window-subheader {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #fff;
    border-bottom: 1px solid #e0e7ff;
    flex-shrink: 0;
}

.chat-filter-icon {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7a99;
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-filter-icon:hover {
    background: #f0f4f8;
}

.chat-filter-active {
    background: linear-gradient(135deg, var(--kz-primary-dark, #1F6B0A), var(--kz-primary, #3D9E0F));
    color: #fff;
}

.chat-filter-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    border-radius: 8px;
    background: var(--kz-secondary, #D6C451);
    color: var(--kz-sidebar-bg, #0D1B12);
    font-size: 9px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-spacer {
    flex: 1;
}

.chat-members-toggle {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    border-radius: 9px;
    cursor: pointer;
    color: #6b7a99;
    font-size: 12px;
    font-weight: 700;
}

.chat-members-toggle:hover {
    background: #f0f4f8;
}

.chat-members-dropdown {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    background: #fff;
    border-bottom: 1px solid #e0e7ff;
    max-height: 160px;
    overflow-y: auto;
    animation: chat-bubble-in 0.16s ease-out;
}

.chat-members-dropdown-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 8px;
    font-size: 12.5px;
    color: #17233d;
}

.chat-members-dropdown-item:hover {
    background: #f5f7fb;
}

.chat-members-admin-tag {
    margin-left: auto;
    font-size: 10px;
    font-weight: 800;
    color: var(--kz-primary-dark, #1F6B0A);
    text-transform: uppercase;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
}

@keyframes chat-bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Message (liste plate, icône + username en en-tête) ──────── */

.chat-msg-item {
    margin-bottom: 50px;
    animation: chat-bubble-in 0.18s ease-out;
}

.chat-msg-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.chat-msg-person-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    padding: 3px;
    color: #fff;
    background: linear-gradient(135deg, var(--kz-primary-dark, #1F6B0A), var(--kz-primary, #3D9E0F));
    box-sizing: border-box;
}

.chat-msg-username {
    font-weight: 800;
    font-size: 12.5px;
    color: var(--kz-primary-dark, #1F6B0A);
}

.chat-msg-time {
    font-size: 10.5px;
    color: #9aa5ba;
    margin-left: auto;
}

.chat-msg-body {
    padding-left: 28px;
}

.chat-msg-text {
    font-size: 13.5px;
    line-height: 1.4;
    color: #17233d;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Lecteur audio custom ────────────────────────────────── */

.chat-audio-player {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 190px;
}

.chat-audio-play {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    flex-shrink: 0;
    cursor: pointer;
    background: var(--kz-secondary, #D6C451);
    position: relative;
}

.chat-audio-icon::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-40%, -50%);
    border-style: solid;
    border-width: 6px 0 6px 9px;
    border-color: transparent transparent transparent var(--kz-sidebar-bg, #0D1B12);
}

.chat-audio-play.playing .chat-audio-icon::before {
    border-style: none;
    width: 3px;
    height: 12px;
    border-left: 3px solid var(--kz-sidebar-bg, #0D1B12);
    border-right: 3px solid var(--kz-sidebar-bg, #0D1B12);
    transform: translate(-50%, -50%);
}

.chat-audio-bar {
    flex: 1;
    height: 5px;
    border-radius: 3px;
    background: rgba(0,0,0,0.12);
    cursor: pointer;
    overflow: hidden;
}


.chat-audio-progress {
    height: 100%;
    width: 0%;
    background: var(--kz-secondary, #D6C451);
    border-radius: 3px;
}

.chat-audio-time {
    font-size: 10.5px;
    flex-shrink: 0;
    min-width: 30px;
}

/* ── Pièces jointes fichier / image ───────────────────────── */

.chat-image-attachment {
    max-width: 200px;
    max-height: 160px;
    border-radius: 10px;
    display: block;
}

.chat-file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(0,0,0,0.04);
    text-decoration: none;
    color: inherit;
}

.chat-file-name {
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* ── Composeur ────────────────────────────────────────────── */

.chat-composer {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    background: #fff;
    border-top: 1px solid #e0e7ff;
    flex-shrink: 0;
}

.chat-composer-input {
    flex: 1;
}

.chat-composer-icon {
    flex-shrink: 0;
}

.chat-recording-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.chat-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--kz-error, #DC2626);
    animation: chat-recording-blink 1s infinite;
}

@keyframes chat-recording-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.chat-recording-time {
    font-size: 12.5px;
    font-weight: 700;
    color: #17233d;
}

.chat-recording-spacer {
    flex: 1;
}

/* ── Dialog gestion de groupe ─────────────────────────────── */

.chat-dialog-section {
    margin-bottom: 16px;
}

.chat-dialog-title {
    font-weight: 800;
    font-size: 13px;
    color: var(--kz-primary-dark, #1F6B0A);
    border-left: 3px solid var(--kz-secondary, #D6C451);
    padding-left: 8px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.chat-membre-list {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-membre-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 10px;
    background: #f5f7fb;
    font-size: 13px;
}

@media (max-width: 480px) {
    .chat-panel {
        width: 96vw;
        height: 90vh;
    }
}
