/**
 * LegiPermis Live Chat Widget - Styles
 * Style iMessage avec bulles bleues/blanches
 */

/* =========================================
   VARIABLES CSS
   ========================================= */
:root {
    --lp-chat-primary: #165799;
    --lp-chat-primary-dark: #0d3d6b;
    --lp-chat-white: #ffffff;
    --lp-chat-gray-light: #f0f0f5;
    --lp-chat-gray: #8e8e93;
    --lp-chat-gray-dark: #636366;
    --lp-chat-bubble-visitor: #165799;
    --lp-chat-bubble-admin: #e9e9eb;
    --lp-chat-text-visitor: #ffffff;
    --lp-chat-text-admin: #1c1c1e;
    --lp-chat-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    --lp-chat-radius: 20px;
    --lp-chat-bubble-radius: 18px;
}

/* =========================================
   BULLE DE CHAT (FERMÉ)
   ========================================= */
.lp-chat-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--lp-chat-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--lp-chat-shadow);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.lp-chat-bubble:hover {
    transform: scale(1.1);
    background: var(--lp-chat-primary-dark);
}

.lp-chat-bubble svg {
    width: 38px;
    height: 32px;
}

.lp-chat-bubble--hidden {
    display: none !important;
}

/* Badge de messages non lus */
.lp-chat-bubble__badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.lp-chat-bubble__badge:empty {
    display: none;
}

/* =========================================
   FENÊTRE DE CHAT (OUVERTE)
   ========================================= */
.lp-chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 520px;
    background: var(--lp-chat-white);
    border-radius: var(--lp-chat-radius);
    box-shadow: -4px 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 10000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.lp-chat-window--open {
    display: flex;
}

/* =========================================
   HEADER
   ========================================= */
.lp-chat-header {
    background: var(--lp-chat-primary);
    color: var(--lp-chat-white);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.lp-chat-header__info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lp-chat-header__avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lp-chat-header__avatar svg {
    width: 24px;
    height: 24px;
    fill: var(--lp-chat-white);
}

.lp-chat-header__title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.1;
    margin: 0;
    color: #ffffff;
}

.lp-chat-header__subtitle {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.1;
    opacity: 0.9;
    margin: 1px 0 0;
    color: #ffffff;
}

.lp-chat-header__close {
    background: transparent;
    border: none;
    color: var(--lp-chat-white);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.lp-chat-header__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lp-chat-header__close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* =========================================
   ZONE DES MESSAGES
   ========================================= */
.lp-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--lp-chat-gray-light);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Scrollbar personnalisée */
.lp-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.lp-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.lp-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Message de bienvenue */
.lp-chat-welcome {
    text-align: center;
    padding: 20px;
    color: var(--lp-chat-gray-dark);
}

.lp-chat-welcome__title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--lp-chat-primary);
}

.lp-chat-welcome__text {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* =========================================
   BULLES DE MESSAGE (style iMessage)
   ========================================= */
.lp-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

/* Message du visiteur (à droite, bleu) */
.lp-chat-message--visitor {
    align-self: flex-end;
}

.lp-chat-message--visitor .lp-chat-message__bubble {
    background: var(--lp-chat-bubble-visitor);
    color: var(--lp-chat-text-visitor);
    border-radius: var(--lp-chat-bubble-radius) var(--lp-chat-bubble-radius) 4px var(--lp-chat-bubble-radius);
}

/* Message de l'admin (à gauche, gris clair) */
.lp-chat-message--admin {
    align-self: flex-start;
}

.lp-chat-message--admin .lp-chat-message__bubble {
    background: var(--lp-chat-bubble-admin);
    color: var(--lp-chat-text-admin);
    border-radius: var(--lp-chat-bubble-radius) var(--lp-chat-bubble-radius) var(--lp-chat-bubble-radius) 4px;
}

.lp-chat-message__bubble {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.lp-chat-message__time {
    font-size: 11px;
    color: var(--lp-chat-gray);
    margin-top: 4px;
    padding: 0 4px;
}

.lp-chat-message--visitor .lp-chat-message__time {
    text-align: right;
}

.lp-chat-message--admin .lp-chat-message__time {
    text-align: left;
}

/* Nom de l'admin */
.lp-chat-message__sender {
    font-size: 12px;
    color: var(--lp-chat-gray-dark);
    font-weight: 500;
    margin-bottom: 4px;
    padding-left: 4px;
}

/* Indicateur de frappe */
.lp-chat-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--lp-chat-bubble-admin);
    border-radius: var(--lp-chat-bubble-radius);
}

.lp-chat-typing__dots {
    display: flex;
    gap: 4px;
}

.lp-chat-typing__dot {
    width: 8px;
    height: 8px;
    background: var(--lp-chat-gray);
    border-radius: 50%;
    animation: lp-typing-bounce 1.4s infinite ease-in-out;
}

.lp-chat-typing__dot:nth-child(1) { animation-delay: -0.32s; }
.lp-chat-typing__dot:nth-child(2) { animation-delay: -0.16s; }
.lp-chat-typing__dot:nth-child(3) { animation-delay: 0s; }

@keyframes lp-typing-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Message système */
.lp-chat-system {
    text-align: center;
    font-size: 12px;
    color: var(--lp-chat-gray);
    padding: 8px;
}

.lp-chat-message--system {
    align-self: center;
    max-width: 90%;
}

.lp-chat-message--system .lp-chat-message__bubble {
    background: #fff3cd;
    color: #856404;
    border-radius: var(--lp-chat-bubble-radius);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
}

/* =========================================
   ZONE DE SAISIE
   ========================================= */
.lp-chat-input {
    padding: 12px 16px;
    background: var(--lp-chat-white);
    border-top: 1px solid #e5e5ea;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.lp-chat-input__field {
    flex: 1;
    border: 1px solid #e5e5ea;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.lp-chat-input__field:focus {
    border-color: var(--lp-chat-primary);
}

.lp-chat-input__field::placeholder {
    color: var(--lp-chat-gray);
}

.lp-chat-input__send {
    width: 40px;
    height: 40px;
    background: var(--lp-chat-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.lp-chat-input__send:hover {
    background: var(--lp-chat-primary-dark);
}

.lp-chat-input__send:active {
    transform: scale(0.95);
}

.lp-chat-input__send:disabled {
    background: var(--lp-chat-gray);
    cursor: not-allowed;
}

.lp-chat-input__send svg {
    width: 20px;
    height: 20px;
    fill: var(--lp-chat-white);
}

/* =========================================
   ÉTAT FERMÉ PAR ADMIN
   ========================================= */
.lp-chat-closed {
    padding: 20px;
    text-align: center;
    background: var(--lp-chat-gray-light);
}

.lp-chat-closed__text {
    font-size: 14px;
    color: var(--lp-chat-gray-dark);
    margin-bottom: 12px;
}

.lp-chat-closed__reopen {
    background: var(--lp-chat-primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.lp-chat-closed__reopen:hover {
    background: var(--lp-chat-primary-dark);
}

/* =========================================
   RESPONSIVE - MOBILE
   ========================================= */
@media (max-width: 480px) {
    /* Overlay blanc avec blur derrière la fenêtre de chat */
    .lp-chat-window--open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.4);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        z-index: -1;
    }

    .lp-chat-window {
        bottom: 10%;
        right: 7.5%;
        left: 7.5%;
        width: 85%;
        max-width: 85vw;
        height: 80%;
        max-height: 80vh;
        border-radius: var(--lp-chat-radius);
    }

    .lp-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .lp-chat-header {
        padding: 12px 16px;
        /* Safe area pour iOS */
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .lp-chat-input {
        padding: 10px 12px;
        /* Safe area pour iOS */
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .lp-chat-messages {
        padding: 12px;
    }

    .lp-chat-message {
        max-width: 85%;
    }
}

/* =========================================
   ANIMATIONS
   ========================================= */
.lp-chat-window {
    animation: lp-chat-slide-up 0.3s ease;
}

@keyframes lp-chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lp-chat-message {
    animation: lp-message-appear 0.2s ease;
}

@keyframes lp-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   ÉTAT HORS LIGNE
   ========================================= */
.lp-chat-offline {
    padding: 20px;
    text-align: center;
}

.lp-chat-offline__icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.5;
}

.lp-chat-offline__text {
    font-size: 14px;
    color: var(--lp-chat-gray-dark);
    line-height: 1.5;
}
