/* Import Poppins Font */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

/* ========== VARIABLES CSS POUR LES THÈMES ========== */
:root {
    /* Mode jour (couleurs actuelles) */
    --bg-gradient: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    --bg-white: #ffffff;
    --bg-container: #ffffff;
    --bg-messages: #ffffff;
    --bg-msg: linear-gradient(135deg, #f8f9fa 0%, #f5f5f5 100%);
    --bg-own-msg: linear-gradient(135deg, #e3f2fd 0%, #e8f4f8 100%);
    --bg-user-info: linear-gradient(135deg, #e3f2fd 0%, #f8f9fa 100%);
    --bg-security: linear-gradient(135deg, #e8f5e8 0%, #f1f8e9 100%);
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #888;
    --text-security: #2e7d32;
    --border-primary: #e0e0e0;
    --border-light: rgba(230, 230, 230, 0.3);
    --border-own: rgba(33, 150, 243, 0.2);
    --border-user: rgba(33, 150, 243, 0.1);
    --scrollbar-track: #f0f0f0;
    --scrollbar-thumb: #888;
    --btn-bg: rgba(255, 255, 255, 0.9);
    --btn-border: rgba(230, 230, 230, 0.5);
}

[data-theme="dark"] {
    /* Mode sombre */
    --bg-gradient: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    --bg-white: #2d2d2d;
    --bg-container: #2d2d2d;
    --bg-messages: #2d2d2d;
    --bg-msg: linear-gradient(135deg, #3a3a3a 0%, #404040 100%);
    --bg-own-msg: linear-gradient(135deg, #1e3a5f 0%, #2d4a6b 100%);
    --bg-user-info: linear-gradient(135deg, #1e3a5f 0%, #2d2d2d 100%);
    --bg-security: linear-gradient(135deg, #1a2e1a 0%, #2a3a2a 100%);
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #888;
    --text-security: #4caf50;
    --border-primary: #444;
    --border-light: rgba(68, 68, 68, 0.5);
    --border-own: rgba(33, 150, 243, 0.3);
    --border-user: rgba(33, 150, 243, 0.2);
    --scrollbar-track: #3a3a3a;
    --scrollbar-thumb: #666;
    --btn-bg: rgba(45, 45, 45, 0.9);
    --btn-border: rgba(68, 68, 68, 0.5);
}

/* Reset some default styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    background: var(--bg-gradient);
    font-family: 'Poppins', Arial, sans-serif;
    margin: 0;
    min-height: 100vh;
    color: var(--text-primary);
}

.chat-container {
    max-width: 850px;
    margin: 25px auto;
    padding: 25px;
    background: var(--bg-container);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(10px);
}

/* ========== HEADER DU CHAT AVEC BOUTON THÈME ========== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    border-radius: 15px;
    color: white;
    box-shadow: 0 4px 16px rgba(25, 118, 210, 0.3);
}

.chat-header h2 {
    margin: 0;
    font-size: 1.5em;
    font-weight: 600;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.theme-toggle .sun { display: block; }
.theme-toggle .moon { display: none; }

[data-theme="dark"] .theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .moon { display: block; }

.security-notice {
    background: var(--bg-security);
    border: 2px solid #4caf50;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
    color: var(--text-security);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.1);
    position: relative;
    overflow: hidden;
}

.security-notice::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 2s ease;
}

.security-notice:hover::before {
    left: 100%;
}

.messages-container {
    height: 520px;
    overflow-y: auto;
    border: 2px solid var(--border-primary);
    padding: 20px;
    margin-bottom: 20px;
    background: var(--bg-messages);
    border-radius: 15px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
}

.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 10px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    transition: background 0.3s ease;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.msg {
    margin-bottom: 18px;
    padding: 16px;
    border-radius: 15px;
    background: var(--bg-msg);
    position: relative;
    border: 1px solid var(--border-light);
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.msg:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.msg.own-message {
    background: var(--bg-own-msg);
    margin-left: 25%;
    border: 1px solid var(--border-own);
}

.msg.own-message:hover {
    box-shadow: 0 4px 16px rgba(33, 150, 243, 0.2);
}

.msg-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.auteur {
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 20px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.auteur:hover {
    transform: scale(1.05);
}

.role-entreprise { 
    background: linear-gradient(135deg, #d32f2f 0%, #b71c1c 100%);
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.3);
}
.role-dirigeant { 
    background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%);
    box-shadow: 0 2px 8px rgba(198, 40, 40, 0.3);
}
.role-lieutenant { 
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}
.role-responsable { 
    background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
    box-shadow: 0 2px 8px rgba(56, 142, 60, 0.3);
}
.role-préparateur { 
    background: linear-gradient(135deg, #f57c00 0%, #ef6c00 100%);
    box-shadow: 0 2px 8px rgba(245, 124, 0, 0.3);
}
.role-preparateur {
    background: linear-gradient(135deg, #f57c00 0%, #ef6c00 100%);
    box-shadow: 0 2px 8px rgba(245, 124, 0, 0.3);
}
.role-livreur { 
    background: linear-gradient(135deg, #7b1fa2 0%, #6a1b9a 100%);
    box-shadow: 0 2px 8px rgba(123, 31, 162, 0.3);
}
.role-ravitailleur { 
    background: linear-gradient(135deg, #5d4037 0%, #4e342e 100%);
    box-shadow: 0 2px 8px rgba(93, 64, 55, 0.3);
}
.role-vendeur { 
    background: linear-gradient(135deg, #c2185b 0%, #ad1457 100%);
    box-shadow: 0 2px 8px rgba(194, 24, 91, 0.3);
}
.role-guetteur { 
    background: linear-gradient(135deg, #455a64 0%, #37474f 100%);
    box-shadow: 0 2px 8px rgba(69, 90, 100, 0.3);
}
.role-standardiste { 
    background: linear-gradient(135deg, #795548 0%, #6d4c41 100%);
    box-shadow: 0 2px 8px rgba(121, 85, 72, 0.3);
}
.role-standartdiste {
    background: linear-gradient(135deg, #795548 0%, #6d4c41 100%);
    box-shadow: 0 2px 8px rgba(121, 85, 72, 0.3);
}
.role-none {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    box-shadow: 0 2px 8px rgba(107, 114, 128, 0.3);
}

.role-system {
    background: linear-gradient(135deg, #0ea5e9 0%, #0369a1 100%);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.role-badge {
    background: linear-gradient(135deg, #666 0%, #555 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(102, 102, 102, 0.2);
    transition: all 0.3s ease;
}

.role-badge.role-entreprise,
.role-badge.role-dirigeant,
.role-badge.role-lieutenant,
.role-badge.role-responsable,
.role-badge.role-preparateur,
.role-badge.role-préparateur,
.role-badge.role-livreur,
.role-badge.role-ravitailleur,
.role-badge.role-vendeur,
.role-badge.role-guetteur,
.role-badge.role-standardiste,
.role-badge.role-standartdiste,
.role-badge.role-system,
.role-badge.role-none {
    filter: saturate(1.05);
}

.role-badge:hover {
    transform: scale(1.05);
}

.system-badge {
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
}

.date {
    color: var(--text-secondary);
    font-size: 0.8em;
    font-weight: 500;
}

.edited {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75em;
    font-weight: 500;
}

.msg-content {
    margin: 12px 0;
    line-height: 1.6;
    color: var(--text-primary);
}

.msg.system-message {
    border-left: 4px solid #0ea5e9;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.08) 0%, rgba(59, 130, 246, 0.05) 100%);
}

.msg.deleted-message {
    border-style: dashed;
    opacity: 0.9;
}

.deleted-text {
    font-style: italic;
    color: var(--text-muted);
}

[data-theme="dark"] .msg.system-message {
    border-left-color: #38bdf8;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.16) 0%, rgba(30, 58, 95, 0.2) 100%);
}

.texte {
    font-size: 0.95em;
    word-wrap: break-word;
}

.msg-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: all 0.3s ease;
}

.msg:hover .msg-actions {
    opacity: 1;
}

.edit-btn, .delete-btn {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(5px);
    color: var(--text-primary);
    font-weight: 500;
}

.edit-btn:hover { 
    background: #e3f2fd;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.2);
}

[data-theme="dark"] .edit-btn:hover {
    background: #1e3a5f;
}

.delete-btn:hover { 
    background: #ffebee;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.2);
}

[data-theme="dark"] .delete-btn:hover {
    background: #5f1e1e;
}

.send-form {
    display: flex;
    gap: 15px;
    align-items: center;
    background: var(--bg-white);
    padding: 20px;
    border-radius: 15px;
    border: 2px solid var(--border-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.send-form input[type="text"] {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid var(--border-primary);
    border-radius: 25px;
    font-size: 14px;
    font-family: 'Poppins', Arial, sans-serif;
    background: var(--bg-white);
    color: var(--text-primary);
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.send-form input[type="text"]::placeholder {
    color: var(--text-muted);
}

.send-form input[type="text"]:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
    transform: scale(1.02);
}

.send-form button {
    padding: 15px 25px;
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
}

.send-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(25, 118, 210, 0.4);
}

.send-form button:active {
    transform: translateY(0);
}

.send-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.composer-meta {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 0 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.char-counter {
    font-weight: 600;
    color: var(--text-secondary);
}

.char-counter.warning {
    color: #f57c00;
}

.char-counter.danger {
    color: #d32f2f;
}

.refresh-state {
    opacity: 0.85;
}

.new-messages-indicator {
    position: sticky;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    margin: -10px auto 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(25, 118, 210, 0.35);
}

.new-messages-indicator:hover {
    transform: translateX(-50%) translateY(-1px);
}

.message-new {
    animation: messageEnter 0.35s ease;
}

@keyframes messageEnter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast-container {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 3000;
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.toast {
    min-width: 220px;
    max-width: 340px;
    background: #1f2937;
    color: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%);
}

.toast-error {
    background: linear-gradient(135deg, #c62828 0%, #8e1a1a 100%);
}

.toast-info {
    background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
}

.action-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.42);
    z-index: 3100;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.action-modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.action-modal-card {
    width: min(92vw, 560px);
    background: var(--bg-container);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: 14px;
    box-shadow: 0 14px 42px rgba(0, 0, 0, 0.28);
    padding: 18px;
    position: relative;
    transform: translateY(8px) scale(0.985);
    transition: transform 0.18s ease;
}

.action-modal.is-open .action-modal-card {
    transform: translateY(0) scale(1);
}

.action-modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}

.action-modal-card h3 {
    margin: 0 0 6px;
    font-size: 1.1rem;
}

.action-modal-card p {
    margin: 0 0 12px;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.action-modal-editor {
    margin-bottom: 12px;
}

.action-modal-editor textarea {
    width: 100%;
    resize: vertical;
    min-height: 90px;
    max-height: 220px;
    border-radius: 10px;
    border: 1px solid var(--border-primary);
    padding: 10px 12px;
    font-family: 'Poppins', Arial, sans-serif;
    font-size: 0.92rem;
    color: var(--text-primary);
    background: var(--bg-white);
}

.action-modal-editor textarea:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.12);
}

.action-modal-meta {
    margin-top: 8px;
    text-align: right;
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.action-modal-meta .warning {
    color: #f57c00;
}

.action-modal-meta .danger {
    color: #d32f2f;
}

.action-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    border: none;
    border-radius: 999px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 600;
}

.modal-btn-cancel {
    background: rgba(107, 114, 128, 0.16);
    color: var(--text-primary);
}

.modal-btn-confirm {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: #fff;
}

.modal-btn-confirm.is-danger {
    background: linear-gradient(135deg, #c62828 0%, #a61d1d 100%);
}

.modal-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .chat-container {
        margin: 15px;
        padding: 15px;
    }
    .chat-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    .messages-container {
        height: 400px;
    }
    .msg.own-message {
        margin-left: 10%;
    }
    .send-form {
        flex-direction: column;
    }
    .composer-meta {
        flex-direction: column;
        align-items: flex-start;
    }
    .toast-container {
        right: 10px;
        left: 10px;
    }
    .toast {
        max-width: none;
    }
    .action-modal-card {
        padding: 14px;
    }
    .action-modal-actions {
        justify-content: stretch;
    }
    .modal-btn {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .chat-header h2 {
        font-size: 1.2em;
    }
    .theme-toggle {
        width: 40px;
        height: 40px;
    }
    .messages-container {
        height: 350px;
    }
    .msg.own-message {
        margin-left: 5%;
    }
}