/* SMS Hub Pro - Upgrades CSS v4 (Return to Classic + Compact Filters) */
/* =================================================================== */

/* 1. LAYOUT GÉNÉRAL (Pour scroll indépendant) */
body, html { height: 100vh !important; overflow: hidden !important; }
.workspace { height: 100vh !important; }
.workspace-main { height: calc(100vh - 64px) !important; }
.left-panel, .center-panel { height: 100% !important; overflow: hidden !important; display: flex !important; flex-direction: column !important; }
.contacts-list { flex: 1 !important; overflow-y: auto !important; height: 100% !important; }
.messages-area { flex: 1 !important; overflow-y: auto !important; height: 100% !important; padding: 20px !important; }
.message-composer { flex-shrink: 0 !important; position: relative !important; }


/* ============================================================================== */
/* 2. ZONE RECHERCHE & FILTRES (Compacifiés sur 2 lignes)                         */
/* ============================================================================== */

/* Conteneur global du haut (Titre + Recherche + Tags) */
.panel-toolbar {
    padding: 8px 12px !important; /* Réduit l'espace autour */
    gap: 6px !important;          /* Réduit l'espace entre recherche et tags */
    flex-shrink: 0 !important;    /* Ne s'écrase pas */
}

/* Champ de recherche plus fin */
.search-box input {
    padding: 6px 8px 6px 32px !important;
    font-size: 12px !important;
    height: 30px !important;      /* Hauteur réduite */
}
.search-box i { top: 50% !important; font-size: 11px !important; }


/* CONTENEUR DES TAGS : Mode Grille / 2 Lignes */
.filter-chips {
    display: flex !important;
    flex-wrap: wrap !important;    /* C'est ça qui crée les lignes multiples */
    gap: 4px !important;           /* Espace entre les boutons */
    overflow-x: hidden !important; /* Plus de scroll horizontal */
    padding: 2px 0 !important;
    justify-content: flex-start !important; /* Aligné à gauche */
}

/* LES BOUTONS (CHIPS) */
.filter-chip {
    /* Taille et Comportement */
    flex: 1 1 auto !important;      /* S'étire légèrement pour remplir les trous */
    width: auto !important;         /* Largeur auto selon le texte */
    min-width: 45px !important;     /* Minimum pour ne pas être écrasé */
    max-width: 30% !important;      /* Max 30% pour en avoir ~3 ou 4 par ligne */

    /* Texte sur 2 lignes si nécessaire */
    white-space: normal !important;
    line-height: 0.95 !important;
    text-align: center !important;

    /* Style Visuel */
    padding: 3px 4px !important;    /* Très compact */
    background: #e2e8f0;
    border-radius: 6px !important;  /* Coins moins ronds pour gagner place */

    font-size: 8.5px !important;
    font-weight: 800 !important;
    color: #475569;
    border: 1px solid transparent;

    display: flex !important; align-items: center !important; justify-content: center !important;
    min-height: 22px !important;
}

.filter-chip:hover { background: #cbd5e1; }
.filter-chip.active {
    background: #0f172a; color: white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ====================================================== */
/* 3. LISTE DES CONTACTS (ALIGNEMENT HEURE CORRIGÉ)       */
/* ====================================================== */
.contacts-list { background: #ffffff !important; }

.contact-item {
    position: relative !important;
    padding: 10px 14px !important;
    height: 64px !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    border-bottom: 1px solid #e2e8f0 !important;
    cursor: pointer !important;
    transition: background 0.2s;
}

.contact-item:hover { background: #525048 !important; }
.contact-item.active { background: #4aa8e6 !important; border-left: 3px solid #0ea5e9 !important; }

/* AVATAR */
.contact-avatar {
    width: 42px !important; height: 42px !important;
    flex-shrink: 0; border-radius: 50% !important;
    background: #f1f5f9; color: #64748b;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 16px; border: 1px solid #e2e8f0;
}

/* BLOC TEXTE CENTRAL */
.contact-details {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    min-width: 0 !important;
}

/* LIGNE DU HAUT (Nom + Tag) */
/* Le sélecteur > div:first-child est CRUCIAL ici */
.contact-details > div:first-child {
    display: flex !important;
    align-items: center !important;
    padding-right: 60px !important; /* Laisse la place pour l'heure */
    margin-bottom: 2px !important;
}

.contact-details strong {
    font-size: 14px !important; color: #0f172a; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* L'HEURE (Alignée parfaitement en haut à droite) */
.contact-time {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: #94a3b8 !important;
    z-index: 2; /* Passe au-dessus de tout */
    background: transparent !important;
}

/* LIGNE DU BAS (Message) */
.contact-details p {
    width: 100% !important;
    font-size: 13px !important;
    color: #64748b !important;
    margin-top: 3px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
}


/* ============================================================
 *  COMPOSER MODERNE COMPACT - Design Final Optimisé
 *  ============================================================ */
.message-composer.modern-compact {
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    border-top: 3px solid var(--primary);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    position: relative;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

/* Zone destinataire pour envoi multiple */
.recipient-zone {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-bottom: 2px solid #fbbf24;
    padding: 12px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.recipient-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
    color: #92400e;
}

.close-recipient {
    margin-left: auto;
    background: none;
    border: none;
    color: #92400e;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-recipient:hover {
    background: rgba(146, 64, 14, 0.1);
}

.recipient-textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #fbbf24;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    background: white;
    color: #78350f;
}

.recipient-textarea::placeholder {
    color: #a16207;
    opacity: 0.7;
}

.recipient-hint {
    font-size: 11px;
    color: #78350f;
    margin-top: 6px;
    font-style: italic;
}

/* Planificateur popup */
.schedule-popup {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 2px solid var(--primary);
    border-radius: 12px;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 320px;
    margin-bottom: 10px;
    animation: popUp 0.3s ease;
}

@keyframes popUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.schedule-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 14px;
    border-radius: 10px 10px 0 0;
}

.close-schedule {
    margin-left: auto;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-schedule:hover {
    background: rgba(255,255,255,0.3);
}

.schedule-body {
    padding: 16px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.schedule-input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.btn-validate-schedule {
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-validate-schedule:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* Barres d'indicateurs */
.file-preview-bar,
.schedule-indicator-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #e0f2fe;
    border-bottom: 1px solid #bae6fd;
    font-size: 13px;
    color: #075985;
    animation: slideDown 0.3s ease;
}

.schedule-indicator-bar {
    background: #fef3c7;
    border-bottom-color: #fde68a;
    color: #92400e;
}

.file-name {
    flex: 1;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-file,
.remove-schedule {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.remove-file:hover,
.remove-schedule:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Barre d'outils compacte */
.composer-toolbar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.toolbar-left {
    display: flex;
    gap: 4px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.char-counter {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    padding: 4px 8px;
    background: var(--bg-main);
    border-radius: 12px;
}

/* Zone de saisie avec bouton flottant */
.composer-input-area {
    position: relative;
    padding: 12px;
    background: var(--bg-main);
}

.auto-expand-textarea {
    width: 100%;
    padding: 12px 60px 12px 12px; /* Espace à droite pour le bouton */
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    font-family: inherit;
    resize: none;
    background: white;
    color: var(--text);
    transition: all 0.2s;
    min-height: 110px; /* 4 lignes de base */
    max-height: 250px; /* Maximum 10 lignes environ */
    overflow-y: auto;
}

.auto-expand-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.auto-expand-textarea::placeholder {
    color: var(--text-muted);
    line-height: 1.6;
}

/* Bouton d'envoi flottant (style Telegram) */
.btn-send-floating {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.btn-send-floating:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.5);
}

.btn-send-floating:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

/* Picker emoji - Version compacte */
.emoji-picker-popup {
    position: absolute;
    bottom: 60px;
    left: 50px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 0;
    z-index: 1000;
    max-width: 380px;
}

.emoji-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 8px 12px;
    border-radius: 10px 10px 0 0;
    font-weight: 600;
    font-size: 13px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    max-height: 320px;
    overflow-y: auto;
}

.emoji-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.emoji-btn:hover {
    background: #f0f0f0;
    transform: scale(1.15);
}

/* Mode nuit */
body.dark-mode .emoji-picker-popup {
    background: #2a2a2a;
    border-color: #444;
}

body.dark-mode .emoji-btn:hover {
    background: #3a3a3a;
}



.spell-check-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #10b981;
    font-weight: 600;
    padding: 4px 8px;
    background: #d1fae5;
    border-radius: 12px;
    margin-right: 8px;
}

.spell-check-badge i {
    font-size: 12px;
}
/* Renforcer la visibilité des erreurs d'orthographe */
.auto-expand-textarea::-webkit-spelling-error {
    text-decoration-color: #ef4444;
    text-decoration-thickness: 2px;
}

.auto-expand-textarea::-moz-spelling-error {
    text-decoration-color: #ef4444;
    text-decoration-thickness: 2px;
}

/* Bouton Nouveau Message - Style bleu */
.tool-btn-new-msg {
    background: var(--primary) !important;
    color: white !important;
    border-color: var(--primary) !important;
}

.tool-btn-new-msg:hover {
    background: var(--primary-hover) !important;
    transform: scale(1.1) !important;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.4) !important;
}

.tool-btn-new-msg:active {
    background: #0369a1 !important;
    transform: scale(1.05) !important;
}

/* ============================================
   MODE NUIT - Styles sombres pour tous les panels
   ============================================ */

[data-mode="dark"] {
    /* Variables globales mode sombre */
     --bg-main: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text: #ffffff;           /* ← Blanc pur au lieu de #f1f5f9 */
    --text-secondary: #e2e8f0; /* ← Plus clair */
    --text-muted: #cbd5e1;     /* ← Plus clair */
    --border: #334155;
}

/* Navbar en haut */
[data-mode="dark"] .navbar {
    background: #0f172a;
    border-bottom-color: #334155;
}

/* Panel gauche - Conversations */
[data-mode="dark"] .left-panel {
    background: #1e293b;
}

[data-mode="dark"] .panel-toolbar {
    background: #1e293b;
}

[data-mode="dark"] .search-box input {
    background: #0f172a !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
}

[data-mode="dark"] .filter-chips .filter-chip {
    background: #334155;
    color: #cbd5e1;
    border-color: #475569;
}

[data-mode="dark"] .filter-chips .filter-chip.active {
    background: var(--primary);
    color: white;
}

[data-mode="dark"] .mark-all-read-btn {
    background: #334155;
    color: #cbd5e1;
}

/* Liste des conversations */
[data-mode="dark"] .contacts-list {
    background: #1e293b;
}

[data-mode="dark"] .contact-item {
    background: #1e293b;
    border-bottom-color: #334155;
}

/* Éléments internes des contacts en mode nuit */
[data-mode="dark"] .contact-item strong {
    color: #ffffff !important;
}

[data-mode="dark"] .contact-item .contact-time {
    color: #94a3b8 !important;
}

[data-mode="dark"] .contact-item p {
    color: #cbd5e1 !important;
}

[data-mode="dark"] .contact-item .contact-details {
    color: #e2e8f0 !important;
}

[data-mode="dark"] .contact-item .contact-details > div {
    color: #ffffff !important;
}



[data-mode="dark"] .contact-item:hover {
    background: #334155;
}

[data-mode="dark"] .contact-item.active {
    background: #475569 !important;  /* Plus clair que #334155 */
}

[data-mode="dark"] .contact-item.active strong,
[data-mode="dark"] .contact-item.active p {
    color: #ffffff !important;
}

/* Panel central - Messages */
[data-mode="dark"] .center-panel {
    background: #0f172a;
}

[data-mode="dark"] .conversation-header {
    background: #1e293b;
    border-bottom-color: #334155;
}

[data-mode="dark"] .messages-area {
    background: #0f172a;
}

[data-mode="dark"] .welcome-message {
    color: #64748b;
}

/* Composer - Zone de saisie */
[data-mode="dark"] .message-composer {
    background: #1e293b;
    border-top-color: #334155;
}

[data-mode="dark"] .composer-toolbar-top {
    background: #334155;
    border-bottom-color: #475569;
}

[data-mode="dark"] .tool-btn {
    background: #1e293b;
    border-color: #475569;
    color: #cbd5e1;
}

[data-mode="dark"] .tool-btn:hover {
    background: var(--primary);
    color: white;
}

[data-mode="dark"] .auto-expand-textarea {
    background: #0f172a !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
}

[data-mode="dark"] .auto-expand-textarea::placeholder {
    color: #94a3b8 !important;
    opacity: 1;
}

[data-mode="dark"] .char-counter {
    color: #64748b;
}

/* Bulles de messages */
[data-mode="dark"] .message-bubble {
    background: #334155;
    color: #f1f5f9;
}

[data-mode="dark"] .message-bubble.sent {
    background: var(--primary);
    color: white;
}

/* Sidebar gauche (SMS/Email/WhatsApp) */
[data-mode="dark"] .channel-sidebar {
    background: #0f172a;
}

[data-mode="dark"] .channel-btn {
    color: #94a3b8;
}

[data-mode="dark"] .channel-btn:hover {
    background: #1e293b;
    color: #cbd5e1;
}

[data-mode="dark"] .channel-btn.active {
    background: var(--primary);
    color: white;
}

/* Bulles reçues - fond sombre */
[data-mode="dark"] .message-bubble.received {
    background: #334155 !important;
    color: #f1f5f9 !important;
}

/* Bulles envoyées - gardent la couleur du thème */
[data-mode="dark"] .message-bubble.sent {
    background: var(--primary) !important;
    color: white !important;
}

/* Timestamps et métadonnées */
[data-mode="dark"] .message-time {
    color: #94a3b8 !important;
}

[data-mode="dark"] .msg-sender {
    color: #cbd5e1 !important;
}

/* ============================================
   BULLES MESSAGES - Style moderne WhatsApp
   ============================================ */

.message {
    display: flex;
    margin-bottom: 16px; /* ← Augmenté de 8px à 16px pour plus d'espace */
    padding: 0 6px;
    animation: fadeIn 0.3s ease;
    clear: both;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Messages reçus - alignés à gauche */
.message.received {
    justify-content: flex-start;
}

.message.received > div {
    background: #e5e7eb;
    color: #1e293b;
    border-radius: 12px 12px 12px 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    padding: 8px 8px;
    max-width: 70%;
    position: relative;
}

/* Messages envoyés - alignés à droite */
.message.sent {
    justify-content: flex-end;
}

.message.sent > div {
    background: #97bfff;
    color: rgb(10, 10, 10);
    border-radius: 12px 12px 2px 12px;
    box-shadow: 0 1px 3px rgba(14, 165, 233, 0.3);
    padding: 8px 8px;
    max-width: 70%;
    position: relative;
}

/* Contenu texte de la bulle */
.msg-content {
    font-size: 14.5px;
    line-height: 1.4;
    word-wrap: break-word;
    margin-bottom: 4px;
}

/* Métadonnées en bas (heure + statut) */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    font-size: 11px;
    margin-top: 4px;
}

.message.sent .msg-meta {
    color: rgba(47, 43, 43, 0.9);
}

.message.received .msg-meta {
    color: #64748b;
}

/* Timestamp */
.msg-time {
    font-size: 12px;
    font-weight: 600; /* ← Plus gras */
    white-space: nowrap;
}

/* Statuts d'envoi (✓✓) */
.message-status {
    font-size: 16px; /* ← Augmenté de 13px à 16px */
    line-height: 1;
    display: inline-flex;
    margin-left: 4px;
    font-weight: 700; /* ← Gras */
}

.message-status.sent::after {
    content: '✓';
    color: rgba(42, 158, 21, 0.75);
}

.message-status.delivered::after {
    content: '✓✓';
    color: rgba(5, 89, 65, 0.75);
}

.message-status.read::after {
    content: '✓✓';
    color: #10b981;
    font-weight: 700;
}

.message-status.failed::after {
    content: '⚠';
    color: #fca5a5;
}

/* Séparateur de date */
.date-separator {
    text-align: center;
    margin: 20px 0 12px 0;
    position: relative;
}

.date-separator span {
    background: #e2e8f0;
    color: #64748b;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Messages programmés */
.message.scheduled > div {
    background: #fef3c7 !important;
    color: #92400e !important;
    border: 1px dashed #fbbf24 !important;
}

.message.scheduled .msg-meta {
    color: #92400e !important;
}

/* ============================================
   LISTE CONVERSATIONS - Fonds alternés
   ============================================ */

/* Fond alterné automatique */
.contact-item:nth-child(odd) {
    background: #ffffff !important;
}

.contact-item:nth-child(even) {
    background: #f9fafb !important;
}

/* Hover plus visible */
.contact-item:hover {
    background: #e0f2fe !important;
}

/* Conversation active bien visible */
.contact-item.active {
    background: #dbeafe !important;
    border-left: 4px solid var(--primary) !important;
}

/* Mode nuit - alternance sombre */
[data-mode="dark"] .contact-item:nth-child(odd) {
    background: #1e293b !important;
}

[data-mode="dark"] .contact-item:nth-child(even) {
    background: #0f172a !important;
}

[data-mode="dark"] .contact-item:hover {
    background: #334155 !important;
}

[data-mode="dark"] .contact-item.active {
    background: #475569 !important;
}

/* ============================================
   MENU CONTEXTUEL (Clic droit)
   ============================================ */

.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    min-width: 220px;
    max-width: 280px;
    z-index: 10000;
    display: none;
    padding: 4px 0;
}

.context-menu.active {
    display: block;
    animation: menuFadeIn 0.15s ease;
}

@keyframes menuFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #334155;
    transition: all 0.15s;
}

.context-menu-item:hover {
    background: #f1f5f9;
}

.context-menu-item i {
    width: 16px;
    text-align: center;
}

.context-menu-item.danger {
    color: #ef4444;
}

.context-menu-item.danger:hover {
    background: #fee2e2;
}

/* --- STYLE DES TAGS (PASTILLES) --- */
.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 8px;
    border: 1px solid transparent;
}

/* Couleurs spécifiques par Tag */
.tag-urgent { background: #fee2e2 !important; color: #991b1b !important; border-color: #fca5a5 !important; }
.tag-rdv { background: #dcfce7 !important; color: #166534 !important; border-color: #86efac !important; }
.tag-attente { background: #fef9c3 !important; color: #854d0e !important; border-color: #fde047 !important; }
.tag-admin { background: #f3e8ff !important; color: #6b21a8 !important; border-color: #d8b4fe !important; }
.tag-pr-info { background: #f1f5f9 !important; color: #334155 !important; border-color: #cbd5e1 !important; }
.tag-done { background: #f1f5f9 !important; color: #475569 !important; border-color: #cbd5e1 !important; }
.tag-default { background: #e2e8f0 !important; color: #475569 !important; }

/* Animation pour l'Urgent */
.tag-urgent {
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* --- BADGE DE NOTIFICATION ROUGE --- */
.unread-badge {
    position: absolute !important;
    top: 4px !important; /* Ajusté pour chevaucher l'avatar */
    left: 35px !important;
    background: #ef4444 !important; /* Rouge vif */
    color: white !important;
    font-size: 10px !important;
    font-weight: 900 !important;
    min-width: 18px !important;
    height: 18px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 2px solid #ffffff !important; /* Cercle blanc autour pour détacher du fond */
    z-index: 10 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2) !important;
}

/* Accentuation de la ligne de conversation non lue */
.contact-item.unread-conv {
    background: #f1f5f9 !important;
    border-left: 4px solid #0ea5e9 !important;
}

.contact-item.unread-conv strong {
    font-weight: 900 !important;
    color: #000 !important;
}

/* ========================================
   CUSTOM DATETIME PICKER - FORMAT FRANÇAIS 24H
   À ajouter à la fin de upgrades.css
   ======================================== */

.schedule-picker {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 0;
    min-width: 320px;
    z-index: 1000;
}

.picker-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px 12px 0 0;
}

.picker-header h4 {
    margin: 0;
    font-size: 16px;
}

.picker-body {
    padding: 16px;
}

.picker-row {
    margin-bottom: 16px;
}

.picker-row label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
    font-size: 14px;
}

.date-inputs, .time-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}

.date-select, .time-select {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.date-select:focus, .time-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.time-select {
    max-width: 70px;
    text-align: center;
    font-weight: 600;
}

.time-separator {
    font-size: 20px;
    font-weight: bold;
    color: #667eea;
}

.picker-preview {
    background: #f0f4ff;
    padding: 12px;
    border-radius: 8px;
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
}

.picker-preview strong {
    color: #667eea;
}

.picker-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
}

.picker-footer button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Mode nuit pour le picker */
body.dark-mode .schedule-picker {
    background: #2a2a2a;
    border-color: #444;
}

body.dark-mode .picker-body {
    color: #e0e0e0;
}

body.dark-mode .picker-row label {
    color: #e0e0e0;
}

body.dark-mode .date-select,
body.dark-mode .time-select {
    background: #1a1a1a;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode .picker-preview {
    background: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .picker-footer {
    border-top-color: #444;
}


/* Meta pour messages programmés */
.msg-meta.scheduled-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.msg-meta.scheduled-meta .msg-time {
    display: block;
}

/* ========================================
   TEMPLATES RAPIDES - VERSION TABLEAU
   ======================================== */

/* Modale de base */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.templates-modal {
    width: 60%;
    max-width: 900px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #e0e0e0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
}

.close-modal {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: white;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
    opacity: 0.8;
}

.close-modal:hover {
    opacity: 1;
}

.modal-body {
    overflow-y: auto;
    padding: 20px;
}

/* Barre de recherche */
.search-bar {
    margin-bottom: 16px;
}

.search-bar input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
}

.search-bar input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Liste avec scroll */
.templates-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
}

/* Tableau */
.templates-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    table-layout: fixed;
}

.templates-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.templates-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
}

.templates-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: background 0.2s;
}

.templates-table tbody tr:hover {
    background: #f8f9fa;
}

.templates-table tbody tr:last-child {
    border-bottom: none;
}

.templates-table td {
    padding: 12px 16px;
    font-size: 13px;
    vertical-align: middle;
}

.template-preview {
    color: #666;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.4;
}

.template-actions-cell {
    text-align: center;
    white-space: nowrap;
}

.template-actions-cell button {
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    margin: 0 2px;
    transition: all 0.2s;
}

.btn-insert {
    background: #2196F3;
    color: white;
}

.btn-insert:hover {
    background: #1976D2;
    transform: scale(1.05);
}

.btn-edit {
    background: #4CAF50;
    color: white;
}

.btn-edit:hover {
    background: #45a049;
    transform: scale(1.05);
}

.btn-delete {
    background: #f44336;
    color: white;
}

.btn-delete:hover {
    background: #da190b;
    transform: scale(1.05);
}

/* Footer avec boutons */
.modal-footer-actions {
    display: flex;
    gap: 10px;
    padding-top: 16px;
    border-top: 2px solid #e0e0e0;
}

.modal-footer-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-add-from-composer {
    background: linear-gradient(135deg, #FF6B6B, #FF8E53);
    color: white;
}

.btn-add-from-composer:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.btn-add-template {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-add-template:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Formulaire */
.template-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin-top: 16px;
    border: 2px solid #667eea;
}

.template-form .form-group {
    margin-bottom: 16px;
}

.template-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.template-form input,
.template-form textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}

.template-form input:focus,
.template-form textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.template-form .char-count {
    display: block;
    text-align: right;
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}

.template-form .form-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.template-form .form-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.loading {
    text-align: center;
    padding: 40px;
    color: #999;
}

/* Mode nuit */
body.dark-mode .modal-content {
    background: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .modal-header {
    border-bottom-color: #333;
}

body.dark-mode .search-bar input {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode .templates-table {
    background: #2a2a2a;
}

body.dark-mode .templates-table tbody tr {
    border-bottom-color: #444;
}

body.dark-mode .templates-table tbody tr:hover {
    background: #333;
}

body.dark-mode .template-preview {
    color: #bbb;
}

body.dark-mode .templates-table td {
    color: #e0e0e0;
}

body.dark-mode .modal-footer-actions {
    border-top-color: #444;
}

body.dark-mode .template-form {
    background: #2a2a2a;
    border-color: #667eea;
}

body.dark-mode .template-form label {
    color: #e0e0e0;
}

body.dark-mode .template-form input,
body.dark-mode .template-form textarea {
    background: #1a1a1a;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode .btn-secondary {
    background: #3a3a3a;
    color: #e0e0e0;
}

body.dark-mode .btn-secondary:hover {
    background: #4a4a4a;
}

/* ===== Séparateur de jour ===== */
.day-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    color: #888;
    font-size: 12px;
}

.day-separator::before,
.day-separator::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #ddd;
}

.day-separator span {
    white-space: nowrap;
    font-weight: 600;
    text-transform: lowercase;
}