/* ==========================================================================
   Groomy.ai Chat Widget — Frontend Styles  v1.2.3
   Variables CSS injectées dynamiquement par PHP (wp_add_inline_style)
   ========================================================================== */

/* Variables par défaut (écrasées par PHP selon la config admin) */
:root {
    --groomy-btn-color:       #4f46e5;
    --groomy-btn-size:        56px;
    --groomy-chat-width:      400px;
    --groomy-chat-height:     600px;
    --groomy-border-radius:   16px;

    /* Position du wrapper */
    --groomy-btn-bottom-val:  24px;
    --groomy-btn-top-val:     auto;
    --groomy-btn-right-val:   24px;
    --groomy-btn-left-val:    auto;

    /* Position du container (au-dessus du bouton) */
    --groomy-container-bottom: auto;
    --groomy-container-top:    auto;
    --groomy-container-right:  auto;
    --groomy-container-left:   auto;
    --groomy-transform-origin: bottom right;
    --groomy-translate-open:   translateY(0) scale(1);
    --groomy-translate-closed: translateY(12px) scale(0.96);

    /* Direction du flex wrapper */
    --groomy-flex-direction: column;
    --groomy-flex-align:     flex-end;
}

/* ------------------------------------------------------------------
   Wrapper flottant (positionne le tout en fixed)
   ------------------------------------------------------------------ */
#groomy-chat-wrapper {
    position: fixed;
    z-index: 9999;

    bottom: var(--groomy-btn-bottom-val);
    top:    var(--groomy-btn-top-val);
    right:  var(--groomy-btn-right-val);
    left:   var(--groomy-btn-left-val);

    display: flex;
    flex-direction: var(--groomy-flex-direction, column);
    align-items: var(--groomy-flex-align, flex-end);
    gap: 10px;
}

/* ------------------------------------------------------------------
   Bouton toggle (relatif au wrapper)
   ------------------------------------------------------------------ */
#groomy-chat-button {
    position: relative;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    width:  var(--groomy-btn-size);
    height: var(--groomy-btn-size);
    border-radius: 50%;
    border: none;
    outline: none;
    cursor: pointer;
    overflow: hidden;

    background-color: var(--groomy-btn-color);
    color: #ffffff;

    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#groomy-chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35);
}

#groomy-chat-button:focus-visible {
    outline: 3px solid var(--groomy-btn-color);
    outline-offset: 3px;
}

/* Icônes et avatar (positionnement absolu centré dans le bouton) */
#groomy-chat-button svg,
#groomy-chat-button .groomy-avatar-img {
    pointer-events: none;
    flex-shrink: 0;
    position: absolute;
    transition: opacity 0.15s ease, transform 0.2s ease;
}

/* Avatar image */
.groomy-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* État fermé : icône chat / avatar visible */
#groomy-chat-button .groomy-icon-open {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* État fermé : icône × cachée */
#groomy-chat-button .groomy-icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

/* État ouvert : swap des icônes */
#groomy-chat-button.is-open .groomy-icon-open {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

#groomy-chat-button.is-open .groomy-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* ------------------------------------------------------------------
   Diode verte "live" (coin bas-droit du bouton)
   ------------------------------------------------------------------ */
.groomy-live-dot {
    position: absolute;
    bottom: 3px;
    right:  3px;
    width:  13px;
    height: 13px;
    background: #22c55e;
    border-radius: 50%;
    border: 2.5px solid #ffffff;
    pointer-events: none;
    animation: groomy-pulse 2.4s ease-in-out infinite;
    transition: opacity 0.2s ease;
    z-index: 1;
}

/* Cache la diode quand le chat est ouvert */
#groomy-chat-button.is-open .groomy-live-dot {
    opacity: 0;
    animation: none;
}

@keyframes groomy-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.55); }
    50%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);    }
    100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0);    }
}

/* ------------------------------------------------------------------
   Bulle tooltip
   ------------------------------------------------------------------ */
#groomy-chat-tooltip {
    display: flex;
    align-items: center;
    gap: 8px;

    background: #ffffff;
    color: #1f2937;
    padding: 10px 12px 10px 14px;
    border-radius: 14px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.13), 0 1px 4px rgba(0, 0, 0, 0.07);

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13.5px;
    line-height: 1.4;
    max-width: 230px;
    white-space: normal;
    cursor: pointer;

    opacity: 1;
    transform: scale(1) translateY(0);
    transition: opacity 0.22s ease, transform 0.22s ease;

    /* Flèche vers le bas par défaut (wrapper bottom = bulle au-dessus du bouton) */
    position: relative;
}

#groomy-chat-tooltip::after {
    content: '';
    position: absolute;
    width:  10px;
    height: 10px;
    background: #ffffff;
    transform: rotate(45deg);
    /* ombre légère sur les côtés exposés */
    box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.06);
}

/* Bulle au-dessus du bouton (position bottom-*) : flèche pointe vers le bas */
#groomy-chat-wrapper[data-pos-v="bottom"] #groomy-chat-tooltip::after {
    bottom: -5px;
}
#groomy-chat-wrapper[data-pos-v="bottom"][data-pos-h="right"] #groomy-chat-tooltip::after {
    right: calc(var(--groomy-btn-size) / 2 - 5px);
}
#groomy-chat-wrapper[data-pos-v="bottom"][data-pos-h="left"] #groomy-chat-tooltip::after {
    left: calc(var(--groomy-btn-size) / 2 - 5px);
}

/* Bulle en-dessous du bouton (position top-*) : flèche pointe vers le haut */
#groomy-chat-wrapper[data-pos-v="top"] #groomy-chat-tooltip::after {
    top: -5px;
    box-shadow: -2px -2px 3px rgba(0, 0, 0, 0.06);
}
#groomy-chat-wrapper[data-pos-v="top"][data-pos-h="right"] #groomy-chat-tooltip::after {
    right: calc(var(--groomy-btn-size) / 2 - 5px);
}
#groomy-chat-wrapper[data-pos-v="top"][data-pos-h="left"] #groomy-chat-tooltip::after {
    left: calc(var(--groomy-btn-size) / 2 - 5px);
}

/* État caché */
#groomy-chat-tooltip.is-hidden {
    opacity: 0;
    transform: scale(0.88) translateY(4px);
    pointer-events: none;
}

/* Texte du tooltip */
.groomy-tooltip-text {
    flex: 1;
}

/* Bouton × pour fermer la bulle */
#groomy-tooltip-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 17px;
    line-height: 1;
    padding: 0 0 0 4px;
    flex-shrink: 0;
    align-self: flex-start;
    transition: color 0.15s;
    pointer-events: auto;
}

#groomy-tooltip-dismiss:hover {
    color: #374151;
}

/* ------------------------------------------------------------------
   Container du chat — ancré près du bouton, PAS d'overlay plein écran
   ------------------------------------------------------------------ */
#groomy-chat-container {
    position: fixed;
    z-index: 9998;

    bottom: var(--groomy-container-bottom);
    top:    var(--groomy-container-top);
    right:  var(--groomy-container-right);
    left:   var(--groomy-container-left);

    width:  var(--groomy-chat-width);
    height: var(--groomy-chat-height);
    border-radius: var(--groomy-border-radius);
    overflow: hidden;

    background: #ffffff;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2), 0 2px 12px rgba(0, 0, 0, 0.08);

    display: none;
    opacity: 0;
    transform: var(--groomy-translate-closed);
    transform-origin: var(--groomy-transform-origin);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

#groomy-chat-container.is-open {
    display: block;
    pointer-events: auto;
}

#groomy-chat-container.is-visible {
    opacity: 1;
    transform: var(--groomy-translate-open);
}

/* ------------------------------------------------------------------
   iframe
   ------------------------------------------------------------------ */
#groomy-chat-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
}

/* ------------------------------------------------------------------
   Bouton fermeture (visible sur mobile)
   ------------------------------------------------------------------ */
#groomy-chat-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10001;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    outline: none;
    cursor: pointer;

    background-color: rgba(255, 255, 255, 0.92);
    color: #374151;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: background-color 0.15s, transform 0.15s;

    opacity: 0;
    pointer-events: none;
}

#groomy-chat-close:hover {
    background-color: #ffffff;
    transform: scale(1.1);
}

#groomy-chat-close:focus-visible {
    outline: 3px solid var(--groomy-btn-color);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------
   Mobile ≤ 768px : plein écran
   ------------------------------------------------------------------ */
@media (max-width: 768px) {
    #groomy-chat-wrapper {
        bottom: 16px !important;
        right:  16px !important;
        top:    auto !important;
        left:   auto !important;
        z-index: 10001;
        flex-direction: column !important;
        align-items: flex-end !important;
    }

    /* Tooltip : visible sur mobile, mais ajusté pour l'écran */
    #groomy-chat-tooltip {
        max-width: 190px;
        font-size: 13px;
        padding: 9px 10px 9px 12px;
    }

    #groomy-chat-container {
        inset: 0 !important;
        width:  100vw !important;
        height: 100vh !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        z-index: 10000;
        transform-origin: bottom right !important;
        /* Bande de 90px en bas où vit le bouton flottant (qui morphe en ×
           quand le chat est ouvert), pour qu'il ne recouvre ni le champ
           de saisie ni le footer "Propulsé par Groomy.ai" de l'iframe */
        padding-bottom: 90px !important;
        box-sizing:     border-box !important;
        background:     #ffffff !important;
    }

    /* Pas de croix interne sur mobile — comme sur desktop, la fermeture
       passe par le bouton flottant principal qui morphe déjà en × */
    #groomy-chat-close {
        display: none !important;
    }
}
