/* Container global */
.combescure-messaging {
    font-family: 'Segoe UI', Roboto, sans-serif;
    max-width: 1000px;
    margin: 0 auto;
    color: #444;
}

/* Header */
.messaging-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #eee;
}

/* Bouton principal */
.btn-primary { 
    background: #d73301; 
    color: white; 
    border: none; 
    padding: 12px 24px; 
    border-radius: 10px; 
    cursor: pointer; 
    font-weight: bold; 
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Filtres */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.filter-item {
    background: #f0f2f5;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #666;
}
.filter-item.active { background: #e8f5e9; color: #2e7d32; }

/* Les Cartes */
.msg-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #eef0f2;
    padding: 20px;
    margin-bottom: 16px;
    display: flex;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    border-left: 5px solid #ddd;
}
.msg-card.is-commande { border-left-color: #3b5998; }
.msg-card.is-annonce { border-left-color: #d73301; }

.card-icon-box {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: #f8f9fa;
}

.card-main { flex-grow: 1; }
.card-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.card-top-row h4 {
    margin: 0;
    font-size: 15px;
    color: #222;
    line-height: 1.3;
}

/* Badges Tags */
.type-tag {
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}
.is-commande .type-tag { background: #e7f3ff; color: #3b5998; }
.is-annonce .type-tag { background: #fff1e7; color: #d73301; }

.status-tag {
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: bold;
}
.status-tag.non-lu { background: #e6fcf5; color: #20c997; }
.status-tag.lu { background: #f1f3f5; color: #868e96; }

.card-excerpt {
    color: #666;
    font-size: 14px;
    margin-top: 10px;
}

/* Bloc Droite */
.card-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
    min-width: 120px;
}
.date-box {
    background: #fff;
    padding: 8px;
    border-radius: 8px;
    font-size: 11px;
    color: #777;
    text-align: right;
}

.btn-read-modern {
    background: #3b5998;
    color: white;
    padding: 10px 18px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    font-size: 13px;
    transition: 0.2s;
}
.btn-read-modern:hover { opacity: 0.9; }
.is-annonce .btn-read-modern { background: #fff; color: #444; border: 1px solid #ddd; }

/* Badge Menu */
.menu-link .menu-msg-badge {
    background-color: #d73301 !important;
    color: #fff !important;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    position: relative;
    top: -10px;
    font-weight: bold;
}

/* Vue discussion */
.combescure-messaging-view {
    max-width: 900px;
    margin: 20px auto;
    font-family: 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    max-width: 100%;
}

.back-to-list { color: #5c79ff; text-decoration: none; font-size: 14px; margin-bottom: 15px; display: inline-block; }

.discussion-main-title { font-size: 24px; color: #333; margin: 10px 0 20px; text-transform: none !important; }

.discussion-container {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
    overflow: hidden;
}

.message-group { display: flex; flex-direction: column; max-width: 85%; }
.message-group.is-other { align-self: flex-start; }
.message-group.is-me { align-self: flex-end; align-items: flex-end; }

.message-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.is-me .message-header { flex-direction: row-reverse; }

.message-header .avatar img { border-radius: 50%; background: #eee; }

.meta { display: flex; flex-direction: column; }
.is-me .meta { text-align: right; }

.sender-name { font-weight: bold; font-size: 14px; color: #333; }
.send-date { font-size: 11px; color: #999; }

.badge-new { 
    background: #e6fcf5; color: #20c997; font-size: 11px; 
    padding: 2px 8px; border-radius: 10px; font-weight: bold; margin-left: 10px;
}

.message-bubble {
    padding: 15px 20px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    overflow: hidden;
    max-width: 100%;
    word-break: break-word;
}

.is-other .message-bubble {
    background: #f0f4f8;
    color: #333;
    border-top-left-radius: 2px;
}

.is-me .message-bubble {
    background: #f1f8f1;
    color: #333;
    border-top-right-radius: 2px;
}

/* Bloquer les largeurs fixes des emails HTML (ex: width="600" en attribut inline) */
.message-bubble table,
.message-bubble td,
.message-bubble th,
.message-bubble div,
.message-bubble center {
    max-width: 100% !important;
    width: auto !important;
    min-width: unset !important;
    box-sizing: border-box !important;
}

.message-bubble img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
    display: block;
}

.message-bubble:has(table) {
    background: #ffffff !important;
    padding: 0 !important;
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

.message-bubble table img {
    max-width: 100% !important;
    height: auto !important;
}

/* Annonces */
.is-annonce .message-bubble {
    background: #ffffff !important;
    border: 1px solid #eef0f2;
    padding: 0 !important;
    overflow: hidden;
    max-width: 100%;
}

.is-annonce .message-bubble img {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 0 20px 0 !important;
    border-radius: 0;
}

.is-annonce .message-bubble p {
    padding: 0 25px 25px 25px;
    font-size: 16px;
    line-height: 1.6;
    color: #444;
    margin: 0;
}

/* Formulaire réponse */
.reply-footer {
    background: #fff;
    border: 1px solid #eee;
    padding: 15px;
    border-radius: 12px;
}

.reply-form { display: flex; gap: 10px; }

.reply-input {
    flex-grow: 1;
    border: 1px solid #eee;
    background: #f9f9f9;
    padding: 12px 20px;
    border-radius: 8px;
    outline: none;
}

.btn-send-reply {
    background: #d73301;
    color: white;
    border: none;
    padding: 0 25px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}

/* Bandeau annonce */
.annonce-info {
    margin-top: 20px;
    font-style: italic;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Désactiver text-transform */
.combescure-messaging h4, 
.combescure-messaging .card-info h4,
.combescure-messaging .sender-name,
.combescure-messaging .message-bubble {
    text-transform: none !important;
}

/* Boutons filtre */
.filter-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 20px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    transition: all 0.2s ease-in-out;
}

.filter-btn:hover:not(.active) {
    background-color: #fdfaf5;
    border-color: #d32f2f;
    color: #d32f2f;
}

.filter-btn.active {
    background: #333;
    color: #fff;
    border-color: #333;
}

.filter-btn[data-filter="non-lu"]:hover:not(.active) {
    background-color: #fcebee;
    border-color: #d32f2f;
    color: #d32f2f;
}

/* ===================== MOBILE ===================== */
@media (max-width: 520px) {

    /* Liste des messages */
    .card-top-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .card-top-row h4 {
        font-size: 14px;
        line-height: 1.3;
        width: 100%;
    }

    .msg-card {
        flex-direction: column;
        gap: 10px;
        padding: 14px;
    }

    .card-icon-box {
        display: none;
    }

    .card-right {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        min-width: unset;
        width: 100%;
    }

    .date-box {
        font-size: 11px;
        text-align: left;
    }

    .btn-read-modern {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Vue discussion */
    .combescure-messaging-view {
        margin: 10px auto;
        padding: 0 4px;
    }

    .discussion-main-title {
        font-size: 18px;
        margin: 8px 0 14px;
    }

    .discussion-container {
        padding: 10px;
        gap: 14px;
    }

    .message-group {
        max-width: 100%;
        width: 100%;
    }

    .message-bubble {
        font-size: 13px;
    }

    .message-bubble table {
        max-width: 100% !important;
        width: auto !important;
        min-width: unset !important;
        font-size: 12px;
    }

    /* Formulaire réponse */
    .reply-footer {
        padding: 12px;
    }

    .reply-form {
        flex-direction: column;
        gap: 10px;
    }

    .reply-input {
        width: 100%;
        padding: 12px 16px;
        font-size: 15px;
    }

    .btn-send-reply {
        width: 100%;
        padding: 14px;
        font-size: 15px;
        text-align: center;
        border-radius: 10px;
    }
}