/* ═══════════════════════════════════════════════════════════
   MÉDIAS & DISCUSSION — sélecteur photo/vocal, pièces jointes
   de course, visionneuse, discussion livreur ↔ gestion.
   ═══════════════════════════════════════════════════════════ */

/* ── Sélecteur photo + vocal ── */
.ml-media-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.ml-media-actions .btn svg {
    flex-shrink: 0;
}

.ml-media-help {
    font-size: .76rem;
    color: var(--text-muted);
}

.ml-media-recording,
.ml-chat-recording {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 4px 12px;
    border-radius: 100px;
    background: var(--orange-soft);
    color: var(--text);
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
}

.ml-media-recording[hidden],
.ml-chat-recording[hidden] {
    display: none;
}

.ml-rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #e5383b;
    animation: ml-rec-pulse 1.1s ease-in-out infinite;
}

@keyframes ml-rec-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.8); }
}

.ml-media-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.ml-media-list[hidden] {
    display: none;
}

.ml-media-item {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--white);
    overflow: visible;
}

.ml-media-item-image img {
    display: block;
    width: 84px;
    height: 84px;
    object-fit: cover;
    border-radius: var(--radius-md);
}

.ml-media-item-audio {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 30px 6px 10px;
    max-width: 100%;
}

.ml-media-item-audio audio {
    height: 34px;
    max-width: 230px;
}

.ml-media-duration {
    font-size: .76rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.ml-media-remove,
.ml-attachment-delete button {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--white);
    background: var(--black);
    color: var(--white);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.ml-media-remove:hover,
.ml-attachment-delete button:hover {
    background: #e5383b;
}

/* ── Pièces jointes d'une course ── */
.ml-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.ml-attachment {
    position: relative;
}

.ml-attachment-thumb img {
    display: block;
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: transform var(--transition);
}

.ml-attachment-thumb:hover img {
    transform: scale(1.02);
}

.ml-attachment-audio {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    font-size: .8rem;
    color: var(--text-muted);
}

.ml-attachment-audio audio {
    height: 36px;
    width: 260px;
    max-width: 100%;
}

.ml-attachment-delete {
    position: absolute;
    top: 0;
    right: 0;
}

/* ── Visionneuse ── */
.ml-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, .86);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 16px;
}

.ml-lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

.ml-lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
}

.ml-lightbox-open {
    position: absolute;
    bottom: 14px;
    color: #fff;
    font-size: .82rem;
    text-decoration: underline;
}

/* ── Filtre du tableau de bord (liste des courses) ── */
.ml-filter-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
    background: var(--orange-soft);
    border: 1px solid var(--orange-glow);
    font-size: .85rem;
}

.ml-chat-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 6px;
    padding: 3px 9px;
    border-radius: 100px;
    background: var(--orange);
    color: var(--white);
    font-size: .76rem;
    font-weight: 700;
    vertical-align: middle;
}

/* ── Discussion ── */
.ml-chat {
    display: flex;
    flex-direction: column;
    scroll-margin-top: calc(var(--header-h) + 12px);
}

.ml-chat-with {
    font-size: .8rem;
    color: var(--text-muted);
}

.ml-chat-body {
    height: 420px;
    overflow-y: auto;
    padding: 14px 16px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 6px;
    overscroll-behavior: contain;
}

.ml-chat-empty,
.ml-chat-closed {
    margin: auto;
    max-width: 320px;
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
}

.ml-chat-closed {
    margin: 0;
    max-width: none;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.ml-chat-day {
    align-self: center;
    margin: 10px 0 4px;
    padding: 2px 10px;
    border-radius: 100px;
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .72rem;
    text-transform: capitalize;
}

.ml-msg {
    max-width: min(78%, 420px);
    padding: 8px 12px 6px;
    border-radius: 16px;
    font-size: .88rem;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.ml-msg.is-other {
    align-self: flex-start;
    background: var(--white);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.ml-msg.is-own {
    align-self: flex-end;
    background: var(--black);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.ml-msg.is-pending {
    opacity: .65;
}

.ml-msg.is-failed {
    background: #fdecec;
    color: #b42318;
    border: 1px solid #f5c2c0;
}

.ml-msg-author {
    font-size: .72rem;
    font-weight: 700;
    color: var(--orange-dark);
    margin-bottom: 2px;
}

.ml-msg.is-own .ml-msg-author {
    color: var(--orange);
}

.ml-msg-image {
    display: block;
    margin: 2px -6px 4px;
}

.ml-msg-image img {
    display: block;
    max-width: 100%;
    max-height: 260px;
    border-radius: 12px;
    object-fit: cover;
}

.ml-msg-audio {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ml-msg-audio audio {
    height: 36px;
    width: 240px;
    max-width: 100%;
}

.ml-msg-audio span {
    font-size: .74rem;
    opacity: .75;
    font-variant-numeric: tabular-nums;
}

.ml-msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: .68rem;
    opacity: .65;
}

.ml-msg-check {
    letter-spacing: -3px;
    margin-right: 3px;
}

.ml-msg.is-read .ml-msg-check {
    color: var(--orange);
    opacity: 1;
}

.ml-chat-composer {
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    background: var(--white);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.ml-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.ml-chat-input[hidden] {
    display: none;
}

.ml-chat-input textarea {
    flex: 1;
    resize: none;
    min-height: 40px;
    max-height: 140px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font: inherit;
    font-size: .9rem;
    background: var(--bg);
    outline: none;
    transition: border-color var(--transition);
}

.ml-chat-input textarea:focus {
    border-color: var(--orange);
    background: var(--white);
}

.ml-chat-icon,
.ml-chat-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.ml-chat-icon {
    background: transparent;
    color: var(--text-muted);
}

.ml-chat-icon:hover {
    background: var(--orange-soft);
    color: var(--orange);
}

.ml-chat-send {
    background: var(--orange);
    color: var(--white);
}

.ml-chat-send:hover {
    background: var(--orange-dark);
}

.ml-chat-icon svg,
.ml-chat-send svg {
    width: 20px;
    height: 20px;
}

.ml-chat-recording {
    width: 100%;
    justify-content: flex-end;
    border-radius: 20px;
    padding: 6px 8px 6px 14px;
}

.ml-chat-recording span:nth-child(2) {
    margin-right: auto;
}

@media (max-width: 640px) {
    .ml-chat-body {
        height: 60vh;
    }

    .ml-msg {
        max-width: 88%;
    }

    .ml-attachment-thumb img {
        width: 96px;
        height: 96px;
    }
}

/* ── Barre d'onglets + filtres (liste des courses) ── */
.ml-toolbar {
    padding: 14px 20px;
}

.ml-segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border);
}

.ml-segmented a {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.ml-segmented a:hover {
    color: var(--text);
}

.ml-segmented a.is-active {
    background: var(--white);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.ml-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ml-filter-search,
.ml-filter-range {
    display: flex;
    align-items: center;
    height: 36px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    transition: border-color var(--transition);
}

.ml-filter-search:focus-within,
.ml-filter-range:focus-within {
    border-color: var(--orange);
}

.ml-filter-search {
    gap: 8px;
    padding: 0 12px;
    width: 230px;
    color: var(--text-muted);
}

.ml-filter-search svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.ml-filter-search input,
.ml-filter-range input {
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: .82rem;
    color: var(--text);
    min-width: 0;
}

.ml-filter-search input {
    flex: 1;
}

.ml-filter-range label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    height: 100%;
}

.ml-filter-range label + label {
    border-left: 1px solid var(--border);
}

.ml-filter-range span {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.ml-filter-range input {
    width: 118px;
}

.ml-filters .btn-sm {
    height: 36px;
}

.ml-filter-reset {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ml-filter-reset:hover {
    color: var(--text);
}

@media (max-width: 640px) {
    .ml-segmented,
    .ml-filters,
    .ml-filter-search,
    .ml-filter-range {
        width: 100%;
    }

    .ml-segmented a {
        flex: 1;
        text-align: center;
    }

    .ml-filter-range label {
        flex: 1;
    }

    .ml-filter-range input {
        width: 100%;
    }

    .ml-filters .btn-sm {
        flex: 1;
    }
}

/* ── Formulaire en ligne (paramétrage : types de course) ── */
.ml-inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ml-inline-form .form-control {
    flex: 1 1 140px;
    width: auto;
}

/* ── Carte des livreurs ── */
.ml-map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
}

.ml-map-card {
    overflow: hidden;
}

.ml-map {
    height: calc(100vh - 230px);
    min-height: 420px;
    z-index: 0;
}

.ml-map-updated {
    font-size: .8rem;
    color: var(--text-muted);
}

.ml-map-count {
    font-size: .8rem;
    font-weight: 700;
    color: var(--text-muted);
}

.ml-map-list {
    max-height: calc(100vh - 290px);
    overflow-y: auto;
}

.ml-map-empty {
    padding: 28px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: .84rem;
    line-height: 1.5;
}

.ml-map-item {
    display: flex;
    gap: 10px;
    width: 100%;
    padding: 12px 18px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: none;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.ml-map-item:hover,
.ml-map-item.is-selected {
    background: var(--bg);
}

.ml-map-item-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ml-map-item-body strong {
    font-size: .86rem;
}

.ml-map-item-body small {
    font-size: .76rem;
    line-height: 1.4;
}

.ml-map-muted {
    color: var(--text-muted);
}

.ml-map-dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    margin-top: 5px;
    border-radius: 50%;
    background: #16a34a;
}

.ml-map-dot.is-busy {
    background: var(--orange);
}

.ml-map-dot.is-stale {
    background: #a3a3a3;
}

.ml-map-pin {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #16a34a;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

.ml-map-pin.is-busy {
    background: var(--orange);
}

.ml-map-pin.is-stale {
    background: #a3a3a3;
}

.ml-map-popup {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
    font-size: .8rem;
}

.ml-map-delivery {
    display: block;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--orange-soft);
    color: var(--text) !important;
    text-decoration: none;
}

.ml-map-call {
    font-weight: 700;
}

@media (max-width: 900px) {
    .ml-map-layout {
        grid-template-columns: 1fr;
    }

    .ml-map {
        height: 60vh;
    }

    .ml-map-list {
        max-height: none;
    }
}

/* ── Destinations d'une course (formulaires complets) ── */
.ml-stops-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.ml-stops {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ml-stop {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.ml-stop.is-delivered {
    background: #f0fdf4;
}

.ml-stop-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-top: 8px;
    border-radius: 50%;
    background: var(--text);
    color: var(--white);
    font-size: .72rem;
    font-weight: 700;
}

.ml-stop-fields {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1.2fr) 100px;
    gap: 8px;
}

.ml-stop-fields .form-group {
    margin: 0;
}

.ml-stop-fee {
    text-align: right;
    font-weight: 600;
}

.ml-stop-remove {
    width: 30px;
    height: 38px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.ml-stop-remove:hover {
    background: #fef2f2;
    color: #dc2626;
}

.ml-stop-badge {
    margin-top: 8px;
}

.ml-stop-error {
    grid-column: 2 / -1;
}

.ml-stops-total {
    margin-top: 8px;
    text-align: right;
    font-size: .84rem;
    color: var(--text-muted);
}

@media (max-width: 760px) {
    .ml-stop-fields {
        grid-template-columns: 1fr 1fr;
    }

    .ml-stop-address {
        grid-column: 1 / -1;
    }
}

.ml-stop-list {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ml-stop-list-fee {
    color: var(--text-muted);
    font-size: .8rem;
    margin-left: 4px;
}

.ml-scheduled {
    color: var(--orange);
    font-weight: 600;
}

.ml-segmented-count {
    display: inline-block;
    min-width: 18px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 100px;
    background: var(--orange);
    color: var(--white);
    font-size: .7rem;
    line-height: 18px;
    text-align: center;
}

/* ── Changement de statut : boutons ── */
.ml-status-current {
    margin-bottom: 12px;
    font-size: .84rem;
    color: var(--text-muted);
}

.ml-status-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 8px;
}

.ml-status-btn {
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    font: inherit;
    font-weight: 700;
    font-size: .86rem;
    text-align: center;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.ml-status-btn.is-orange { color: var(--orange-dark, #e05f00); border-color: var(--orange-glow); }
.ml-status-btn.is-orange:hover,
.ml-status-btn.is-orange.is-active { background: var(--orange); border-color: var(--orange); color: var(--white); }
.ml-status-btn.is-green { color: #15803d; border-color: #bbf7d0; }
.ml-status-btn.is-green:hover { background: #16a34a; border-color: #16a34a; color: var(--white); }
.ml-status-btn.is-red { color: #b91c1c; border-color: #fecaca; }
.ml-status-btn.is-red:hover { background: #dc2626; border-color: #dc2626; color: var(--white); }
.ml-status-btn.is-gray { color: var(--text); }
.ml-status-btn.is-gray:hover,
.ml-status-btn.is-black:hover { background: var(--text); border-color: var(--text); color: var(--white); }
.ml-status-btn.is-black { color: var(--text); }

.ml-status-assign {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--orange-glow);
    border-radius: var(--radius-md);
    background: var(--orange-soft);
}

.ml-map-links {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
