/* ============================================================
   IP SERVICE CHAT — WIDGET FRONTEND
   ============================================================ */

#ipsc-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ipsc-accent: #4f46e5;
    --ipsc-accent-h: #4338ca;
    --ipsc-radius: 16px;
    --ipsc-shadow: 0 8px 40px rgba(0,0,0,.18);
}

/* ── BOUTON FLOTTANT ── */
#ipsc-toggle {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--ipsc-accent);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform .2s, box-shadow .2s;
    position: relative;
    outline: none;
}
#ipsc-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(0,0,0,.32);
}
#ipsc-toggle:active { transform: scale(.96); }

/* Pulse animation */
#ipsc-toggle::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--ipsc-accent);
    animation: ipsc-pulse 2.5s ease-in-out infinite;
    opacity: .5;
}
@keyframes ipsc-pulse {
    0%, 100% { transform: scale(1); opacity: .5; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* Badge non-lu */
#ipsc-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: .65rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: ipsc-bounce .4s ease;
}
@keyframes ipsc-bounce {
    0% { transform: scale(0); }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ── FENÊTRE CHAT ── */
#ipsc-window {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    background: #fff;
    border-radius: var(--ipsc-radius);
    box-shadow: var(--ipsc-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: ipsc-slideUp .25s ease;
    max-height: 560px;
}
@keyframes ipsc-slideUp {
    from { opacity: 0; transform: translateY(16px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── HEADER ── */
.ipsc-header {
    background: var(--ipsc-accent);
    color: #fff;
    padding: 1rem 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ipsc-header-info { display: flex; align-items: center; gap: .75rem; }
.ipsc-avatar {
    width: 40px; height: 40px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0;
}
.ipsc-agent-name { font-weight: 800; font-size: .95rem; }
.ipsc-status { font-size: .75rem; opacity: .9; margin-top: .15rem; display: flex; align-items: center; gap: .3rem; }
.ipsc-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; display: inline-block; flex-shrink: 0;
    animation: ipsc-blink 2s ease-in-out infinite;
}
.ipsc-dot.offline { background: #fbbf24; animation: none; }
@keyframes ipsc-blink { 0%,100%{opacity:1} 50%{opacity:.4} }
.ipsc-close-btn {
    background: rgba(255,255,255,.15); border: none; color: #fff;
    width: 28px; height: 28px; border-radius: 8px;
    cursor: pointer; font-size: .85rem; display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.ipsc-close-btn:hover { background: rgba(255,255,255,.3); }

/* ── ÉTAPES ── */
.ipsc-step { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── FORMULAIRE DE DÉMARRAGE ── */
#ipsc-start-form { padding: 1.25rem; gap: .85rem; }
.ipsc-welcome-box {
    background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-radius: 12px;
    padding: 1.1rem;
    text-align: center;
}
.ipsc-welcome-emoji { font-size: 1.75rem; margin-bottom: .4rem; }
.ipsc-welcome-text { font-size: .875rem; color: #374151; font-weight: 600; line-height: 1.5; margin: 0; }
.ipsc-field-group { display: flex; flex-direction: column; gap: .6rem; }
.ipsc-field-group input,
.ipsc-field-group textarea {
    width: 100%;
    border: 1.5px solid #e5e7eb;
    border-radius: 9px;
    padding: .65rem .9rem;
    font-family: inherit;
    font-size: .875rem;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    resize: none;
    color: #111827;
}
.ipsc-field-group input:focus,
.ipsc-field-group textarea:focus {
    border-color: var(--ipsc-accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.ipsc-send-start {
    width: 100%;
    background: var(--ipsc-accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: .8rem;
    font-family: inherit;
    font-size: .9rem;
    font-weight: 800;
    cursor: pointer;
    transition: background .15s, transform .1s;
    display: flex; align-items: center; justify-content: center; gap: .5rem;
}
.ipsc-send-start:hover { background: var(--ipsc-accent-h, #4338ca); transform: translateY(-1px); }
.ipsc-send-start:disabled { opacity: .6; cursor: not-allowed; }
.ipsc-privacy { font-size: .72rem; color: #9ca3af; text-align: center; margin: 0; }

/* ── VUE CONVERSATION ── */
#ipsc-chat-view { display: flex; flex-direction: column; height: 100%; }
.ipsc-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    scroll-behavior: smooth;
    min-height: 0;
    max-height: 340px;
}
.ipsc-messages-container::-webkit-scrollbar { width: 4px; }
.ipsc-messages-container::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }

/* Bulles */
.ipsc-msg {
    max-width: 82%;
    padding: .65rem .9rem;
    border-radius: 14px;
    font-size: .875rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: ipsc-msgIn .2s ease;
}
@keyframes ipsc-msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ipsc-msg-visitor {
    background: var(--ipsc-accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.ipsc-msg-agent {
    background: #f3f4f6;
    color: #111827;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.ipsc-msg-time {
    font-size: .65rem;
    opacity: .6;
    margin-top: .2rem;
    text-align: right;
}
.ipsc-msg-agent .ipsc-msg-time { text-align: left; }
.ipsc-msg-sender { font-size: .7rem; font-weight: 800; opacity: .7; margin-bottom: .15rem; }

/* Indicateur de frappe */
.ipsc-typing-indicator {
    padding: .5rem 1rem;
    display: flex; gap: .3rem; align-items: center;
}
.ipsc-typing-indicator span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #d1d5db; animation: ipsc-typing 1.2s ease-in-out infinite;
}
.ipsc-typing-indicator span:nth-child(2) { animation-delay: .2s; }
.ipsc-typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes ipsc-typing { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-5px)} }

/* Zone de saisie */
.ipsc-input-area {
    display: flex;
    gap: .5rem;
    padding: .75rem;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}
#ipsc-message-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: .6rem .85rem;
    font-family: inherit;
    font-size: .875rem;
    resize: none;
    outline: none;
    max-height: 80px;
    overflow-y: auto;
    line-height: 1.5;
    transition: border-color .15s;
}
#ipsc-message-input:focus { border-color: var(--ipsc-accent); }
#ipsc-send-btn {
    width: 38px; height: 38px;
    background: var(--ipsc-accent);
    border: none; border-radius: 10px;
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .1s;
    flex-shrink: 0;
    align-self: flex-end;
}
#ipsc-send-btn:hover { background: var(--ipsc-accent-h, #4338ca); transform: translateY(-1px); }

.ipsc-chat-footer {
    padding: .4rem .75rem .6rem;
    text-align: center;
    flex-shrink: 0;
}
.ipsc-close-conv-btn {
    background: none; border: none;
    font-size: .72rem; color: #9ca3af;
    cursor: pointer; font-family: inherit;
    text-decoration: underline;
    transition: color .15s;
}
.ipsc-close-conv-btn:hover { color: #ef4444; }

/* ── VUE FERMÉE ── */
#ipsc-closed-view { align-items: center; justify-content: center; }
.ipsc-closed-box {
    text-align: center;
    padding: 2rem 1.5rem;
}
.ipsc-closed-box h3 { font-size: 1rem; font-weight: 900; margin-bottom: .5rem; color: #111827; }
.ipsc-closed-box p  { font-size: .875rem; color: #6b7280; margin: 0; }
.ipsc-new-chat {
    margin-top: 1.25rem;
    background: var(--ipsc-accent);
    color: #fff; border: none; border-radius: 9px;
    padding: .65rem 1.5rem;
    font-family: inherit; font-size: .875rem; font-weight: 700;
    cursor: pointer; transition: background .15s;
}
.ipsc-new-chat:hover { background: var(--ipsc-accent-h, #4338ca); }

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
    #ipsc-window { width: calc(100vw - 16px); right: 8px; left: 8px; bottom: 80px; }
    #ipsc-widget { right: 16px; bottom: 16px; }
}
