/*
 * Styles de ChatView (js/chatview.js).
 * FICHIER PARTAGÉ : même copie dans Integratik/Ressources/Arbix/css/chatview.css (Xibra). Modifier les deux ensemble.
 * Couleurs et rayons : variables --cv-* (redéfinies par l'hôte au besoin).
 */
.cv {
    --cv-primary: #134F48;
    --cv-primary-dark: #0E3B36;
    --cv-accent: #9DBF00;
    --cv-accent-soft: #E4EEC0;
    --cv-active: #EEF3DC;
    --cv-surface: #FFFFFF;
    --cv-thread-bg: #F8F4EE;
    --cv-border: #E3DACB;
    --cv-text: #1C2B29;
    --cv-text-2: #3D4D4A;
    --cv-muted: #5A6B68;
    --cv-read: #2A7FB8;
    --cv-note-bg: #FFF4CC;
    --cv-note-border: #B8962E;
    --cv-note-text: #6B5310;
    --cv-radius: 20px;
    --cv-font: inherit;

    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 20px;
    height: 100%;
    min-height: 0;
    position: relative;
    font-family: var(--cv-font);
    color: var(--cv-text);
}

.cv *, .cv *::before, .cv *::after { box-sizing: border-box; }

.cv-icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

.cv button { font: inherit; color: inherit; }

.cv-btn-icon {
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 50%;
    border: 1px solid var(--cv-border);
    background: var(--cv-surface);
    color: var(--cv-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.cv-btn-icon:hover { background: var(--cv-active); }
.cv-btn-icon:focus-visible, .cv-conv:focus-visible, .cv-btn-send:focus-visible, .cv-quote:focus-visible, .cv-filter:focus-visible {
    outline: 3px solid var(--cv-accent);
    outline-offset: 2px;
}

/* ---------- Liste ---------- */
.cv-list, .cv-thread, .cv-empty {
    background: var(--cv-surface);
    border-radius: var(--cv-radius);
    min-height: 0;
    overflow: hidden;
}

.cv-list { display: flex; flex-direction: column; }
.cv-list-head { padding: 20px 20px 10px; display: flex; flex-direction: column; gap: 12px; }
.cv-list-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cv-list-title { margin: 0; font-size: 26px; font-weight: 600; color: var(--cv-primary); font-family: var(--cv-font-display, inherit); }
.cv-btn-new { background: var(--cv-accent); border-color: var(--cv-accent); color: var(--cv-primary-dark); }
.cv-btn-new:hover { background: #B2D41A; }

.cv-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--cv-thread-bg);
    border: 1px solid var(--cv-border);
    border-radius: 60px;
    padding: 0 16px;
    height: 44px;
    color: var(--cv-muted);
}
.cv-search-input { border: 0; background: transparent; font: inherit; font-size: 15px; flex: 1; min-width: 0; outline: none; color: var(--cv-text); }
.cv-search:focus-within { border-color: var(--cv-primary); }

.cv-filters { display: flex; gap: 6px; }
.cv-filter {
    flex: 1;
    height: 38px;
    border-radius: 60px;
    border: 1px solid var(--cv-border);
    background: var(--cv-surface);
    font-size: 13px !important;
    font-weight: 700;
    color: var(--cv-text-2) !important;
    cursor: pointer;
}
.cv-filter[aria-selected="true"] { background: var(--cv-primary); border-color: var(--cv-primary); color: #FFFFFF !important; }

.cv-convs { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.cv-convs-empty { padding: 24px 16px; color: var(--cv-muted); font-size: 14px; text-align: center; }

.cv-conv {
    width: 100%;
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.cv-conv:hover { background: var(--cv-thread-bg); }
.cv-conv.is-active { background: var(--cv-active); }

.cv-avatar {
    width: 48px;
    height: 48px;
    flex: none;
    border-radius: 50%;
    background: var(--cv-primary);
    color: #F2EADF;
    font-weight: 800;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cv-avatar--team { border-radius: 14px; background: var(--cv-accent-soft); color: var(--cv-primary); }

.cv-conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.cv-conv-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cv-conv-title, .cv-conv-preview, .cv-conv-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-conv-title { font-size: 15px; font-weight: 600; }
.cv-conv-sub { font-size: 12px; color: var(--cv-muted); }
.cv-conv-preview { font-size: 13px; color: var(--cv-muted); }
.cv-conv-time { font-size: 12px; color: var(--cv-muted); flex: none; }
.cv-conv.is-unread .cv-conv-title { font-weight: 800; }
.cv-conv.is-unread .cv-conv-preview { font-weight: 700; color: var(--cv-text); }
.cv-conv.is-unread .cv-conv-time { font-weight: 800; color: var(--cv-primary); }

.cv-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--cv-accent);
    color: var(--cv-primary-dark);
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

/* ---------- Fil ---------- */
.cv-thread { display: flex; flex-direction: column; }
.cv-thread[hidden], .cv-empty[hidden] { display: none; }

.cv-thread-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid #EDE5D8;
}
.cv-btn-back { display: none; border: 0; }
.cv-thread-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cv-thread-title { margin: 0; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-thread-subtitle { font-size: 13px; color: var(--cv-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-thread-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.cv-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--cv-thread-bg);
    padding: 16px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
}

.cv-loading { margin: auto; color: var(--cv-muted); font-size: 14px; padding: 24px; text-align: center; }

.cv-more {
    align-self: center;
    border: 1px solid var(--cv-border);
    background: var(--cv-surface);
    border-radius: 60px;
    padding: 8px 16px;
    font-size: 13px !important;
    font-weight: 700;
    color: var(--cv-primary) !important;
    cursor: pointer;
    margin-bottom: 8px;
}

.cv-day, .cv-unread-sep { display: flex; align-items: center; justify-content: center; margin: 12px 0 8px; }
.cv-day span {
    background: var(--cv-surface);
    border: 1px solid var(--cv-border);
    color: var(--cv-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 5px 14px;
    border-radius: 60px;
}
.cv-unread-sep { gap: 12px; }
.cv-unread-sep::before, .cv-unread-sep::after { content: ""; flex: 1; height: 1px; background: var(--cv-accent); }
.cv-unread-sep span { font-size: 12px; font-weight: 800; color: var(--cv-primary); background: var(--cv-accent-soft); padding: 5px 12px; border-radius: 60px; }

.cv-row { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.cv-row--cont { margin-top: 2px; }
.cv-row--me { flex-direction: row-reverse; }
.cv-row.is-flash .cv-bubble { outline: 3px solid var(--cv-accent); }

.cv-bubble {
    position: relative;
    max-width: min(560px, 82%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px 6px;
    border-radius: 18px 18px 18px 4px;
    background: var(--cv-surface);
    box-shadow: 0 1px 1px rgba(19, 79, 72, 0.08);
    min-width: 0;
}
.cv-row--me .cv-bubble { background: var(--cv-accent-soft); border-radius: 18px 18px 4px 18px; }
.cv-row--cont .cv-bubble { border-radius: 18px; }
.cv-bubble.has-likes { margin-bottom: 14px; }
.cv-bubble--note, .cv-row--me .cv-bubble--note { background: var(--cv-note-bg); border: 1px dashed var(--cv-note-border); }

.cv-note-label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; color: var(--cv-note-text); }
.cv-note-label .cv-icon { width: 14px; height: 14px; }

.cv-author { font-size: 13px; font-weight: 800; color: var(--cv-primary); }

.cv-quote {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
    border: 0;
    border-left: 0;
    background: rgba(19, 79, 72, 0.07);
    border-radius: 10px;
    padding: 7px 12px;
    cursor: pointer;
    min-width: 0;
}
.cv-quote-author { font-size: 12px; font-weight: 800; color: var(--cv-primary); }
.cv-quote-text { font-size: 13px; color: var(--cv-text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.cv-text { font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.cv-text a { color: var(--cv-primary); text-decoration: underline; }

.cv-images { display: grid; gap: 4px; }
.cv-images--grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cv-image { display: block; border-radius: 12px; overflow: hidden; background: var(--cv-thread-bg); }
.cv-image img { display: block; width: 100%; max-width: 360px; max-height: 320px; object-fit: cover; }
.cv-images--grid .cv-image img { height: 160px; }

.cv-file {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--cv-thread-bg);
    border: 1px solid var(--cv-border);
    border-radius: 12px;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--cv-text);
    min-width: 0;
}
.cv-file:hover { border-color: var(--cv-primary); }
.cv-file-ext {
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 10px;
    background: var(--cv-primary);
    color: #F2EADF;
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.cv-file-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.cv-file-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-file-size { font-size: 12px; color: var(--cv-muted); }
.cv-file .cv-icon { color: var(--cv-primary); }

.cv-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; font-size: 11px; color: var(--cv-muted); }
.cv-receipt { display: inline-flex; }
.cv-receipt .cv-icon { width: 16px; height: 16px; }
.cv-read { color: var(--cv-read); }

.cv-likes {
    position: absolute;
    bottom: -14px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--cv-surface);
    border: 1px solid var(--cv-border);
    border-radius: 60px;
    padding: 1px 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--cv-primary);
}
.cv-row--me .cv-likes { right: auto; left: 10px; }
.cv-likes .cv-icon { width: 14px; height: 14px; fill: var(--cv-accent); stroke: var(--cv-primary); stroke-width: 1.8; }
.cv-likes.is-mine { border-color: var(--cv-accent); }

.cv-msg-actions { display: flex; flex-direction: column; gap: 2px; opacity: 0; transition: opacity 0.12s; }
.cv-row:hover .cv-msg-actions, .cv-row:focus-within .cv-msg-actions { opacity: 1; }
.cv-act { width: 32px; height: 32px; border: 0; background: transparent; color: var(--cv-muted); }
.cv-act .cv-icon { width: 16px; height: 16px; }
.cv-act.is-on { color: var(--cv-primary); }
.cv-act.is-on .cv-icon { fill: var(--cv-accent); }

/* ---------- Saisie ---------- */
.cv-composer { border-top: 1px solid #EDE5D8; padding: 10px 16px 14px; display: flex; flex-direction: column; gap: 8px; background: var(--cv-surface); }
.cv-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.cv-file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.cv-input-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    background: var(--cv-thread-bg);
    border: 1px solid var(--cv-border);
    border-radius: 24px;
    padding: 11px 18px;
}
.cv-input-wrap:focus-within { border-color: var(--cv-primary); }
.cv-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    color: var(--cv-text);
    max-height: 160px;
    padding: 0;
}
.cv--note .cv-input-wrap { background: var(--cv-note-bg); border-color: var(--cv-note-border); }

.cv-btn-send {
    width: 48px;
    height: 48px;
    flex: none;
    border-radius: 50%;
    border: 0;
    background: var(--cv-accent);
    color: var(--cv-primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.cv-btn-send:hover { background: #B2D41A; }
.cv-btn-send:disabled { opacity: 0.6; cursor: progress; }

.cv-reply-preview { display: flex; align-items: center; gap: 12px; background: var(--cv-thread-bg); border-radius: 12px; padding: 6px 6px 6px 14px; color: var(--cv-primary); }
.cv-reply-preview[hidden], .cv-files-preview[hidden], .cv-note-toggle[hidden] { display: none; }
.cv-reply-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cv-reply-author { font-size: 12px; font-weight: 800; }
.cv-reply-text { font-size: 13px; color: var(--cv-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-reply-preview .cv-btn-icon { border: 0; background: transparent; color: var(--cv-muted); }

.cv-files-preview { display: flex; gap: 8px; flex-wrap: wrap; }
.cv-chip { display: flex; align-items: center; gap: 8px; background: var(--cv-thread-bg); border: 1px solid var(--cv-border); border-radius: 12px; padding: 4px 4px 4px 4px; max-width: 240px; }
.cv-chip img, .cv-chip .cv-file-ext { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.cv-chip-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.cv-chip-remove { width: 32px; height: 32px; border: 0; background: transparent; color: var(--cv-muted); }

.cv-note-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--cv-note-text); cursor: pointer; align-self: flex-start; }
.cv-note-toggle .cv-icon { width: 16px; height: 16px; }
.cv-note-check { width: 18px; height: 18px; accent-color: var(--cv-primary); margin: 0; }

/* ---------- Vide, messages d'erreur ---------- */
.cv-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--cv-muted); padding: 32px; text-align: center; }
.cv-empty-icon { width: 72px; height: 72px; border-radius: 50%; background: var(--cv-accent-soft); color: var(--cv-primary); display: flex; align-items: center; justify-content: center; }
.cv-empty-icon .cv-icon { width: 32px; height: 32px; }

.cv-toast {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: var(--cv-primary-dark);
    color: #FFFFFF;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 14px;
    max-width: min(90%, 480px);
    box-shadow: 0 10px 30px rgba(14, 59, 54, 0.3);
    z-index: 5;
}
.cv-toast[hidden] { display: none; }

/* ---------- Tactile ---------- */
@media (hover: none) {
    .cv-msg-actions { opacity: 1; }
}

/* ---------- Mobile : un seul panneau à la fois ---------- */
@media (max-width: 760px) {
    .cv { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .cv-list, .cv-thread, .cv-empty { border-radius: 0; }
    .cv-empty { display: none; }
    .cv--thread-open .cv-list { display: none; }
    .cv-btn-back { display: inline-flex; }
    .cv-thread-head { padding: 10px 12px 10px 4px; }
    .cv-thread-head .cv-avatar { width: 40px; height: 40px; font-size: 14px; }
    .cv-messages { padding: 12px 10px 20px; }
    .cv-composer { padding: 8px 8px calc(10px + env(safe-area-inset-bottom)); }
    .cv-composer-row { gap: 4px; }
    .cv-btn-attach, .cv-btn-photo { border: 0; background: transparent; }
    .cv-bubble { max-width: 86%; }
    .cv-act { width: 28px; height: 28px; }
}
