/* Bulle de chat flottante sitewide — voir views/partials/chat-widget.php,
   App\Controllers\ChatWidgetController (2026-08-04, plan "Ticketing
   multi-marque + chat temps réel"). Couleurs alignées sur le thème du site
   principal (--pillar-color #fd7200), pas sur le violet du dashboard.
   Réécrit le 2026-08-05 : vue liste + vue fil (plusieurs conversations en
   parallèle), badge de non-lus. */

/* Le `hidden` HTML est sinon écrasé par `display:flex` ci-dessous — un
   attribut seul perd face à une règle de classe de même origine (author)
   même si la spécificité UA [hidden] est identique. */
.chatw-panel[hidden],
.chatw-list-view[hidden],
.chatw-thread-view[hidden],
.chatw-precontact[hidden],
.chatw-icon-btn[hidden],
.chatw-badge[hidden] {
    display: none;
}

.chatw-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9998;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.chatw-bubble {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #fd7200, #fd1d1d);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(253, 114, 0, .35);
    transition: transform .2s;
}

.chatw-bubble:hover { transform: scale(1.06); }

.chatw-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #dc2626;
    color: #fff;
    font-size: .7rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px #fff;
}

.chatw-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 460px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatw-header {
    background: linear-gradient(135deg, #fd7200, #fd1d1d);
    color: #fff;
    padding: .85rem 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: .95rem;
}

.chatw-header span#chatw-title { flex: 1; }

.chatw-icon-btn,
.chatw-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0 .25rem;
    display: flex;
    align-items: center;
}

.chatw-close { font-size: 1.4rem; line-height: 1; }

/* ── Vue liste ────────────────────────────────────────────────────────── */

.chatw-list-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff3e6;
}

.chatw-convo-list {
    flex: 1;
    overflow-y: auto;
    padding: .6rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.chatw-list-empty {
    text-align: center;
    color: #9a7a5c;
    font-size: .85rem;
    padding: 2rem 1rem;
    margin: 0;
}

.chatw-convo-group-title {
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #b45309;
    padding: .4rem .2rem 0;
}

.chatw-convo-group-title:first-child { padding-top: 0; }

.chatw-convo-row {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    text-align: left;
    background: #fff;
    border: none;
    border-radius: 10px;
    padding: .65rem .8rem;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
    font-family: inherit;
}

.chatw-convo-row:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .1); }

.chatw-convo-date {
    font-size: .85rem;
    font-weight: 600;
    color: #1f2937;
}

.chatw-convo-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.chatw-convo-status {
    font-size: .72rem;
    color: #6b7280;
}

.chatw-convo-unread {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #dc2626;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatw-new-btn {
    margin: .6rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #fd7200, #fd1d1d);
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    padding: .65rem;
    cursor: pointer;
}

/* ── Vue fil ──────────────────────────────────────────────────────────── */

.chatw-thread-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chatw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: #fff3e6;
}

.chatw-msg {
    max-width: 80%;
    padding: .55rem .8rem;
    border-radius: 12px;
    font-size: .85rem;
    line-height: 1.5;
}

.chatw-msg-client {
    align-self: flex-end;
    background: #fd7200;
    color: #fff;
    border-bottom-right-radius: 3px;
}

.chatw-msg-agent {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.chatw-msg-meta {
    margin-top: .3rem;
    font-size: .68rem;
    opacity: .75;
}

.chatw-msg-client .chatw-msg-meta { text-align: right; }

.chatw-precontact,
.chatw-form {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: .85rem;
    border-top: 1px solid #eee;
}

.chatw-form { flex-direction: row; align-items: flex-end; }

.chatw-precontact input,
.chatw-precontact select,
.chatw-precontact textarea,
.chatw-form textarea {
    width: 100%;
    box-sizing: border-box;
    padding: .55rem .7rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: .85rem;
    font-family: inherit;
    resize: none;
    background: #fff;
}

.chatw-form textarea { flex: 1; }

.chatw-send-btn {
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #fd7200, #fd1d1d);
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    padding: .6rem .9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatw-send-btn-wide { width: 100%; }

.chatw-error {
    margin: 0 .85rem .5rem;
    color: #dc2626;
    font-size: .78rem;
}

@media (max-width: 480px) {
    .chatw-root { right: 12px; bottom: 12px; }
    .chatw-panel { width: calc(100vw - 24px); }
}
