/*
 * Tanshell IA Bot — Styles du widget de chat front-end
 * Style épuré, Apple-inspired : blanc, gris séparateur, bulles bleues utilisateur.
 */

/* ===========================================================================
   Variables CSS (surchargées dynamiquement depuis PHP)
=========================================================================== */
:root {
    --tib-primary:      #0071e3;
    --tib-user-bubble:  #0071e3;
    --tib-bot-bubble:   #f0f0f5;
    --tib-bg:           #ffffff;
    --tib-border:       #d1d1d6;
    --tib-text:         #1c1c1e;
    --tib-text-light:   #6e6e73;
    --tib-radius:       18px;
    --tib-shadow:       0 8px 32px rgba(0, 0, 0, 0.15);
    --tib-toggle-size:  58px;
    --tib-z:            99999;
    --tib-chat-width:   360px;
    --tib-chat-height:  520px;
    --tib-bottom:       24px;
    --tib-side:         24px;
}

/* ===========================================================================
   Wrapper principal (positionnement fixe)
=========================================================================== */
.tib-wrapper {
    position: fixed;
    bottom: var(--tib-bottom);
    z-index: var(--tib-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.tib-wrapper.tib-right {
    right: var(--tib-side);
    align-items: flex-end;
}

.tib-wrapper.tib-left {
    left: var(--tib-side);
    align-items: flex-start;
}

/* ===========================================================================
   Bulle de bienvenue
=========================================================================== */
.tib-welcome-bubble {
    background: var(--tib-bg);
    border: 1px solid var(--tib-border);
    border-radius: 12px;
    padding: 10px 14px;
    max-width: 240px;
    font-size: 14px;
    color: var(--tib-text);
    box-shadow: var(--tib-shadow);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.4;
    animation: tib-fade-in 0.3s ease;
}

.tib-bubble-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tib-text-light);
    font-size: 12px;
    padding: 0;
    flex-shrink: 0;
    line-height: 1;
}

.tib-bubble-close:hover {
    color: var(--tib-text);
}

/* ===========================================================================
   Bouton flottant
=========================================================================== */
.tib-toggle {
    width: var(--tib-toggle-size);
    height: var(--tib-toggle-size);
    border-radius: 50%;
    background: var(--tib-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    padding: 0;
    overflow: visible;
}

.tib-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.tib-toggle:active {
    transform: scale(0.96);
}

.tib-toggle svg {
    width: 26px;
    height: 26px;
    pointer-events: none;
}

.tib-toggle-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* --- Icônes du bouton : état fermé / ouvert --- */
.tib-toggle-icon,
.tib-toggle-close {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* État par défaut : icône bot visible, croix cachée */
.tib-toggle-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.tib-toggle-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.7);
}

.tib-toggle-close svg {
    width: 22px;
    height: 22px;
}

/* État ouvert : croix visible, icône bot cachée */
.tib-toggle--open .tib-toggle-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.7);
}

.tib-toggle--open .tib-toggle-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Masque la pastille "en ligne" quand le chat est ouvert */
.tib-toggle--open .tib-online-dot {
    display: none;
}

/* Pastille verte "en ligne" */
.tib-online-dot {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 12px;
    height: 12px;
    background: #34c759;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* ===========================================================================
   Fenêtre de chat
=========================================================================== */
.tib-chat {
    background: var(--tib-bg);
    border: 1px solid var(--tib-border);
    border-radius: var(--tib-radius);
    box-shadow: var(--tib-shadow);
    width: var(--tib-chat-width);
    height: var(--tib-chat-height);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tib-slide-up 0.25s ease;
}

.tib-chat[hidden] {
    display: none;
}

/* Animation d'ouverture */
@keyframes tib-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes tib-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ===========================================================================
   En-tête
=========================================================================== */
.tib-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--tib-border);
    background: var(--tib-bg);
    flex-shrink: 0;
}

.tib-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.tib-header-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--tib-text);
    flex: 1;
}

.tib-header-online {
    width: 9px;
    height: 9px;
    background: #34c759;
    border-radius: 50%;
    flex-shrink: 0;
}

.tib-header-close,
.tib-header-reset,
.tib-close-minimal {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tib-text-light);
    font-size: 18px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.15s;
    flex-shrink: 0;
}

.tib-header-close:hover,
.tib-header-reset:hover,
.tib-close-minimal:hover {
    color: var(--tib-text);
}

/* Bouton reset : icône SVG légèrement plus petite */
.tib-header-reset svg {
    width: 16px;
    height: 16px;
    display: block;
}

.tib-close-minimal {
    align-self: flex-end;
    margin: 8px 10px 0;
}

/* Conteneur des boutons minimaux (sans en-tête) */
.tib-minimal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    padding: 8px 10px 0;
}

/* ===========================================================================
   Zone de messages
=========================================================================== */
.tib-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

/* Scrollbar discrète */
.tib-messages::-webkit-scrollbar {
    width: 4px;
}
.tib-messages::-webkit-scrollbar-track {
    background: transparent;
}
.tib-messages::-webkit-scrollbar-thumb {
    background: var(--tib-border);
    border-radius: 4px;
}

/* Bulles de messages */
.tib-message {
    max-width: 80%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.tib-message--user {
    background: var(--tib-user-bubble);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.tib-message--bot {
    background: var(--tib-bot-bubble);
    color: var(--tib-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* ===========================================================================
   Indicateur "est en train d'écrire"
=========================================================================== */
.tib-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px 6px;
    flex-shrink: 0;
}

.tib-typing[hidden] {
    display: none;
}

.tib-typing-dot {
    width: 7px;
    height: 7px;
    background: var(--tib-text-light);
    border-radius: 50%;
    animation: tib-bounce 1.2s infinite ease-in-out;
}

.tib-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.tib-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes tib-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-5px); }
}

/* ===========================================================================
   Zone de saisie
=========================================================================== */
.tib-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--tib-border);
    background: var(--tib-bg);
    flex-shrink: 0;
}

.tib-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--tib-border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--tib-text);
    background: #f8f8fa;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color 0.15s;
    line-height: 1.5;
}

.tib-input:focus {
    border-color: var(--tib-primary);
    background: #fff;
}

.tib-input::placeholder {
    color: var(--tib-text-light);
}

.tib-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tib-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
    padding: 0;
}

.tib-send:hover {
    background: color-mix(in srgb, var(--tib-primary) 85%, #000);
}

.tib-send:active {
    transform: scale(0.92);
}

.tib-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.tib-send svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* ===========================================================================
   Responsive mobile — plein écran
=========================================================================== */
@media (max-width: 480px) {
    /* Le chat ouvert couvre tout l'écran, indépendamment du wrapper */
    .tib-chat:not([hidden]) {
        position: fixed;
        inset: 0;
        width: 100% !important;
        height: 100dvh !important;
        border-radius: 0;
        border: none;
        box-shadow: none;
        /* z-index légèrement supérieur pour passer au-dessus du bouton toggle */
        z-index: calc(var(--tib-z) + 1);
        animation: tib-slide-mobile 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    }

    @keyframes tib-slide-mobile {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    /* Bouton toggle : reste visible mais en-dessous du chat plein écran */
    .tib-wrapper {
        --tib-side:   16px;
        --tib-bottom: 16px;
    }

    /* Bulle de bienvenue : réduite sur mobile */
    .tib-welcome-bubble {
        max-width: calc(100vw - 96px);
        font-size: 13px;
    }

    /* Zone de saisie : padding safe area pour les iPhones avec barre de geste */
    .tib-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}
