/* =====================================================================
   CONVERSATIONS SITE WEB — la console de l'équipe (public/js/web-chat.js)
   =====================================================================
   Deux volets : liste à gauche, conversation à droite. Sur mobile, la liste
   puis le détail plein écran (.show-pane, même patron que .chat-view dans
   shell.css). Jetons --gs-* uniquement (DA-GANDALF §3) : le sombre bascule
   tout seul. Rayons : 8 px contrôles, 10 px cartes/bulles, capsules 999 px
   réservées aux pastilles de statut (DA §5).
   ===================================================================== */

.web-chat-view {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    background: var(--gs-ground);
    color: var(--gs-ink);
    min-height: 0;
    overflow: hidden;
}
/* Desktop : cadre fixé entre l'en-tête universel et le bas, comme #ai-chat-view
   (ux-refresh.css) — hauteur déterministe, composeur toujours visible. */
@media (min-width: 861px) {
    body.shell-on .web-chat-view {
        position: fixed;
        inset: var(--gs-universal-h, 72px) 0 0 var(--gs-rail-w);
        z-index: 50;
    }
    body.gs-popup-mode .web-chat-view { inset: 0; }
}

/* ---- Liste ---- */
.wc-list {
    display: flex; flex-direction: column; min-height: 0;
    border-right: 1px solid var(--gs-line);
    background: var(--gs-panel);
}
.wc-list-head { padding: 16px 16px 8px; border-bottom: 1px solid var(--gs-line); }
.wc-eyebrow {
    color: var(--gs-ink-faint); font-size: 10px; font-weight: 700;
    letter-spacing: .09em; text-transform: uppercase; margin-bottom: 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wc-tabs { display: flex; gap: 8px; }
.wc-tab {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 36px; padding: 0 12px;
    border: 1px solid var(--gs-line); border-radius: var(--gs-radius-control, 8px);
    background: var(--gs-panel); color: var(--gs-ink-dim);
    font: 600 12.5px/1.2 'Inter', system-ui, sans-serif; cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.wc-tab:hover { background: var(--gs-panel-2); color: var(--gs-ink); }
.wc-tab.on { background: var(--gs-ink); color: var(--gs-panel); border-color: var(--gs-ink); }
.wc-tab:focus-visible { outline: 2px solid var(--gs-accent); outline-offset: 2px; }
.wc-tab-count {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    display: inline-grid; place-items: center;
    background: var(--gs-crit); color: #fff; font-size: 10.5px; font-weight: 700;
}
.wc-tab.on .wc-tab-count { background: var(--gs-panel); color: var(--gs-ink); }

.wc-items { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.wc-item {
    width: 100%; display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px;
    align-items: center; padding: 10px; margin-bottom: 2px;
    border: 1px solid transparent; border-radius: var(--gs-radius-card, 10px);
    background: transparent; color: var(--gs-ink); text-align: left; cursor: pointer;
    font-family: inherit; transition: background .15s ease, border-color .15s ease;
}
.wc-item:hover { background: var(--gs-panel-2); }
.wc-item.on { background: var(--gs-accent-soft); border-color: var(--gs-line-strong); }
.wc-item:focus-visible { outline: 2px solid var(--gs-accent); outline-offset: -2px; }
/* Une ligne en attente porte un liseré d'avertissement : repère périphérique,
   le titre reste en encre (DA §3.2). */
.wc-item-attente { box-shadow: inset 3px 0 0 var(--gs-warn); }
.wc-item-body { min-width: 0; display: grid; gap: 3px; }
.wc-item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.wc-item-name { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wc-item.unanswered .wc-item-name { font-weight: 750; }
.wc-item-time { flex: 0 0 auto; color: var(--gs-ink-faint); font-size: 11px; font-weight: 600; }
.wc-item-attente .wc-item-time { color: var(--gs-warn); }
.wc-item-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.wc-item-excerpt { flex: 1; min-width: 0; color: var(--gs-ink-dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wc-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--gs-crit); }
.wc-item-terminee { opacity: .78; }

.wc-vide { padding: 28px 16px; text-align: center; color: var(--gs-ink-faint); font-size: 13px; display: grid; gap: 12px; justify-items: center; }
.wc-vide p { margin: 0; max-width: 34ch; line-height: 1.45; }

/* ---- Avatars (ronds : sémantique personne, DA §5) ---- */
.wc-avatar {
    width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
    display: grid; place-items: center;
    background: var(--gs-brand-beige); color: var(--gs-brand-earth);
    font: 700 15px/1 'Outfit', 'Inter', sans-serif;
}
.wc-avatar-sm { width: 36px; height: 36px; font-size: 14px; }

/* ---- Détail ---- */
.wc-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.wc-empty { flex: 1; display: grid; place-items: center; color: var(--gs-ink-faint); font-size: 14px; padding: 24px; text-align: center; }
.wc-conv { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.wc-conv.hidden { display: none; }

.wc-head {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    align-items: center; gap: 12px;
    padding: 12px 24px; border-bottom: 1px solid var(--gs-line); background: var(--gs-panel);
}
.wc-back {
    display: none; min-width: 40px; min-height: 40px; padding: 0 10px;
    border: 1px solid var(--gs-line); border-radius: var(--gs-radius-control, 8px);
    background: var(--gs-panel); color: var(--gs-ink-dim); font-size: 16px; cursor: pointer;
}
.wc-who { min-width: 0; }
.wc-name { font: 700 16px/1.25 'Outfit', 'Inter', sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wc-meta { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--gs-ink-faint); font-size: 11.5px; margin-top: 2px; }
.wc-lang {
    flex: 0 0 auto; padding: 1px 6px; border: 1px solid var(--gs-line); border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; font-weight: 600; color: var(--gs-ink-dim);
}
.wc-page { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--gs-ink-faint); text-decoration: none; }
.wc-page[href] { color: var(--gs-accent); }
.wc-page[href]:hover { text-decoration: underline; }
.wc-state { display: grid; justify-items: end; gap: 4px; }
.wc-badge {
    display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 700; white-space: nowrap;
    background: var(--gs-panel-2); color: var(--gs-ink-dim); border: 1px solid var(--gs-line);
}
.wc-badge-attente { background: color-mix(in srgb, var(--gs-warn) 14%, var(--gs-panel)); color: var(--gs-warn); border-color: color-mix(in srgb, var(--gs-warn) 40%, transparent); }
.wc-badge-encours { background: color-mix(in srgb, var(--gs-ok) 14%, var(--gs-panel)); color: var(--gs-ok); border-color: color-mix(in srgb, var(--gs-ok) 40%, transparent); }
.wc-badge-terminee { background: var(--gs-panel-2); color: var(--gs-ink-faint); }
.wc-presence { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--gs-ink-faint); white-space: nowrap; }
.wc-presence:not(:empty)::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--gs-ink-faint); }
.wc-presence-en_ligne { color: var(--gs-ok); }
.wc-presence-en_ligne::before { background: var(--gs-ok); }
.wc-presence-vu { color: var(--gs-warn); }
.wc-presence-vu::before { background: var(--gs-warn); }
.wc-actions { display: flex; gap: 8px; }

/* Boutons : géométrie GANDALF (8 px), primaire terre / secondaire panneau (DA §9.1). */
.wc-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; padding: 0 14px;
    border: 1px solid var(--gs-line-strong); border-radius: var(--gs-radius-control, 8px);
    background: var(--gs-panel); color: var(--gs-ink);
    font: 600 13px/1 'Inter', system-ui, sans-serif; cursor: pointer;
    transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.wc-btn:hover { background: var(--gs-panel-2); transform: translateY(-1px); }
.wc-btn:active { transform: none; }
.wc-btn:focus-visible { outline: 2px solid var(--gs-accent); outline-offset: 2px; }
.wc-btn:disabled { opacity: .55; cursor: default; transform: none; }
.wc-btn-primary { background: var(--gs-brand-earth); color: #fff; border-color: var(--gs-brand-earth); }
.wc-btn-primary:hover { background: var(--gs-brand-earth); filter: brightness(1.12); }
body.shell-on[data-gtheme="dark"] .wc-btn-primary { background: var(--gs-brand-beige); color: var(--gs-brand-earth); border-color: var(--gs-brand-beige); }
.wc-btn-sm { min-height: 32px; padding: 0 10px; font-size: 12px; }

.wc-notice {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 12px 24px 0; padding: 10px 14px;
    border: 1px solid var(--gs-line); border-radius: var(--gs-radius-card, 10px);
    background: var(--gs-panel-2); color: var(--gs-ink); font-size: 13px;
}
.wc-notice-warn { border-color: color-mix(in srgb, var(--gs-warn) 45%, transparent); background: color-mix(in srgb, var(--gs-warn) 10%, var(--gs-panel)); }
.wc-notice.hidden { display: none; }

/* ---- Le fil ---- */
.wc-thread {
    flex: 1; min-height: 0; overflow-y: auto; padding: 16px 24px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--gs-ground);
    background-image: radial-gradient(var(--gs-brand-fibre) 1px, transparent 1px);
    background-size: 40px 40px;
}
.wc-day { display: flex; align-items: center; gap: 12px; margin: 6px 0; color: var(--gs-ink-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.wc-day::before, .wc-day::after { content: ''; flex: 1; height: 1px; background: var(--gs-line); }
.wc-row { display: flex; align-items: flex-end; gap: 8px; max-width: 78%; }
.wc-row-agent { align-self: flex-end; flex-direction: row-reverse; }
.wc-bubble {
    min-width: 0; padding: 8px 12px 9px;
    border: 1px solid var(--gs-line); border-radius: var(--gs-radius-card, 10px);
    background: var(--gs-panel); color: var(--gs-ink);
}
.wc-row-agent .wc-bubble { background: var(--gs-accent-soft); border-color: var(--gs-line-strong); }
/* L'assistant IA : même côté que le client, atténué — c'est le contexte, pas
   la personne qu'on sert. */
.wc-row-assistant { padding-left: 44px; }
.wc-row-assistant .wc-bubble { background: var(--gs-panel-2); border-style: dashed; opacity: .82; }
.wc-bubble-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; font-size: 11px; color: var(--gs-ink-faint); }
.wc-row-agent .wc-bubble-head { flex-direction: row-reverse; }
.wc-bubble-who { font-weight: 700; color: var(--gs-ink-dim); }
.wc-row-assistant .wc-bubble-who { font-style: italic; }
.wc-bubble-time { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; }
.wc-bubble-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.wc-bubble-text a { color: var(--gs-accent); text-decoration: underline; }

/* ---- Composeur ---- */
.wc-composer {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; align-items: end;
    padding: 12px 24px; border-top: 1px solid var(--gs-line); background: var(--gs-panel);
}
.wc-input {
    width: 100%; min-height: 40px; max-height: 200px; padding: 9px 12px; resize: none;
    border: 1px solid var(--gs-line); border-radius: var(--gs-radius-control, 8px);
    background: var(--gs-ground); color: var(--gs-ink);
    font: 400 14px/1.45 'Inter', system-ui, sans-serif; box-sizing: border-box;
}
.wc-input:focus { outline: none; border-color: var(--gs-accent); box-shadow: 0 0 0 3px var(--gs-accent-soft); }
.wc-input:disabled { background: var(--gs-panel-2); color: var(--gs-ink-faint); }
.wc-send { min-height: 40px; }
.wc-hint { grid-column: 1 / -1; min-height: 0; color: var(--gs-ink-faint); font-size: 11.5px; }
.wc-hint:empty { display: none; }

/* ---- Mobile : liste puis détail plein écran ---- */
@media (max-width: 860px) {
    body.shell-on .web-chat-view {
        position: fixed; left: 0; right: 0;
        top: calc(47px + env(safe-area-inset-top));
        bottom: calc(var(--gs-tabbar-h, 62px) + env(safe-area-inset-bottom));
        z-index: 50; grid-template-columns: 1fr;
    }
    .web-chat-view .wc-list { border-right: none; }
    .web-chat-view .wc-pane { display: none; }
    .web-chat-view.show-pane .wc-list { display: none; }
    .web-chat-view.show-pane .wc-pane { display: flex; }
    .web-chat-view .wc-back { display: inline-flex; align-items: center; justify-content: center; }
    /* Conversation ouverte = immersive : ni topbar ni tabbar (façon chat.js). */
    body.shell-on:has(.web-chat-view.show-pane:not(.hidden)) .gshell-topbar { display: none; }
    body.shell-on:has(.web-chat-view.show-pane:not(.hidden)) .gshell-tabbar { display: none; }
    body.shell-on .web-chat-view.show-pane { top: env(safe-area-inset-top); bottom: 0; }
    .wc-head { grid-template-columns: auto auto minmax(0, 1fr); gap: 10px; padding: 10px 14px; }
    .wc-state { grid-column: 2 / -1; justify-items: start; grid-auto-flow: column; gap: 10px; }
    .wc-actions { grid-column: 1 / -1; }
    .wc-actions .wc-btn { flex: 1; min-height: 44px; }
    .wc-thread { padding: 12px 14px; }
    .wc-row { max-width: 88%; }
    .wc-notice { margin: 10px 14px 0; }
    .wc-composer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
    body.shell-on.kb-open .wc-composer { padding-bottom: 10px; }
    .wc-input { font-size: 16px; } /* iOS : sous 16 px, le focus zoome la page */
    .wc-send { min-height: 44px; }
    .wc-item { min-height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
    .wc-tab, .wc-item, .wc-btn { transition: none; }
    .wc-btn:hover { transform: none; }
}
