/**
 * ============================================
 * CHATBOT WIDGET - Styles
 * Agence IA Aix - Dynamic Creative
 * 
 * Design aligné avec le site principal
 * Inclut : glow, animations, micro-interactions
 * ============================================
 */

/* ============================================
   VARIABLES CSS (héritées du site)
   ============================================ */
:root {
    /* Couleurs principales */
    --chat-primary: #00f0ff;
    --chat-primary-glow: rgba(0, 240, 255, 0.4);
    --chat-secondary: #7b61ff;
    --chat-accent: #ff6b35;
    
    /* Gradient signature */
    --chat-gradient-ai: linear-gradient(135deg, #00f0ff 0%, #7b61ff 50%, #ff6b35 100%);
    --chat-gradient-glow: radial-gradient(ellipse at center, rgba(0, 240, 255, 0.15) 0%, transparent 70%);
    
    /* Couleurs de fond */
    --chat-dark: #0a0a0f;
    --chat-dark-lighter: #12121a;
    --chat-dark-card: rgba(26, 26, 37, 0.95);
    
    /* Couleurs de texte */
    --chat-text: #ffffff;
    --chat-text-muted: #8a8a9a;
    
    /* Dimensions */
    --chat-width: 400px;
    --chat-height: 550px;
    --chat-toggle-size: 64px;
    --chat-border-radius: 24px;
    --chat-input-radius: 12px;
    
    /* Positionnement */
    --chat-bottom: 24px;
    --chat-right: 24px;
    
    /* Ombres & Glow */
    --chat-shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --chat-shadow-glow: 0 0 30px var(--chat-primary-glow);
    --chat-shadow-glow-strong: 0 15px 40px rgba(0, 240, 255, 0.3);
    
    /* Transitions */
    --chat-transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --chat-transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chat-transition-bounce: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    
    /* Z-index */
    --chat-z-index: 9998;
}

/* ============================================
   CONTENEUR PRINCIPAL
   ============================================ */
#chat-widget {
    position: fixed;
    bottom: var(--chat-bottom);
    right: var(--chat-right);
    z-index: var(--chat-z-index);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================
   BOUTON TOGGLE FLOTTANT
   ============================================ */
#chat-toggle {
    width: var(--chat-toggle-size);
    height: var(--chat-toggle-size);
    border-radius: 50%;
    background: var(--chat-gradient-ai);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chat-dark);
    box-shadow: var(--chat-shadow-glow), var(--chat-shadow-soft);
    transition: all var(--chat-transition-normal);
    position: relative;
    overflow: hidden;
}

/* Effet de pulsation subtil */
#chat-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--chat-gradient-ai);
    opacity: 0;
    z-index: -1;
    animation: chatTogglePulse 2s ease-in-out infinite;
}

@keyframes chatTogglePulse {
    0%, 100% { 
        transform: scale(1);
        opacity: 0;
    }
    50% { 
        transform: scale(1.15);
        opacity: 0.3;
    }
}

/* Effet shimmer au hover */
#chat-toggle::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

#chat-toggle:hover::after {
    transform: translateX(100%);
}

#chat-toggle:hover {
    transform: scale(1.1) translateY(-3px);
    box-shadow: var(--chat-shadow-glow-strong), 0 20px 40px rgba(0, 0, 0, 0.4);
}

#chat-toggle:active {
    transform: scale(0.95);
}

#chat-toggle svg {
    width: 28px;
    height: 28px;
    transition: transform var(--chat-transition-normal);
}

#chat-toggle:hover svg {
    transform: rotate(-10deg);
}

/* ============================================
   FENÊTRE DE CHAT
   ============================================ */
#chat-window {
    position: absolute;
    bottom: calc(var(--chat-toggle-size) + 20px);
    right: 0;
    width: var(--chat-width);
    max-width: calc(100vw - 48px);
    height: var(--chat-height);
    max-height: calc(100vh - 150px);
    background: var(--chat-dark-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--chat-border-radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--chat-shadow-glow), 0 25px 60px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

/* Gradient line on top (comme les cards du site) */
#chat-window::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--chat-gradient-ai);
    z-index: 10;
}

/* Glow effect */
#chat-window::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 80%;
    height: 80%;
    background: var(--chat-gradient-glow);
    pointer-events: none;
    z-index: 0;
}

#chat-window.open {
    display: flex;
    animation: chatWindowOpen var(--chat-transition-normal);
}

@keyframes chatWindowOpen {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   HEADER
   ============================================ */
#chat-header {
    padding: 20px;
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.08), rgba(123, 97, 255, 0.08));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}

#chat-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

#chat-avatar {
    width: 48px;
    height: 48px;
    background: var(--chat-gradient-ai);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 240, 255, 0.2);
}

/* Ring animé autour de l'avatar */
#chat-avatar::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--chat-primary);
    animation: chatAvatarSpin 3s linear infinite;
}

@keyframes chatAvatarSpin {
    to { transform: rotate(360deg); }
}

#chat-title {
    color: var(--chat-text);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
}

#chat-status {
    color: var(--chat-primary);
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--chat-primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--chat-primary);
    animation: chatStatusPulse 2s ease-in-out infinite;
}

@keyframes chatStatusPulse {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.5;
        transform: scale(1.2);
    }
}

#chat-close {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--chat-text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--chat-transition-fast);
}

#chat-close:hover {
    background: rgba(255, 107, 53, 0.1);
    border-color: var(--chat-accent);
    color: var(--chat-accent);
    transform: rotate(90deg);
}

/* ============================================
   ZONE DES MESSAGES
   ============================================ */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.2) 100%);
}

/* Scrollbar personnalisée style site */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--chat-primary), var(--chat-secondary));
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-primary);
}

/* ============================================
   MESSAGES (bulles)
   ============================================ */
.chat-message {
    display: flex;
    max-width: 85%;
    animation: chatMessageIn var(--chat-transition-normal);
}

@keyframes chatMessageIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-bubble {
    padding: 14px 18px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
}

/* Bulle utilisateur - Gradient AI */
.chat-message.user .chat-bubble {
    background: var(--chat-gradient-ai);
    color: var(--chat-dark);
    font-weight: 500;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 4px 15px rgba(0, 240, 255, 0.2);
}

/* Bulle assistant - Style glass */
.chat-message.assistant .chat-bubble {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--chat-text);
    border-radius: 18px 18px 18px 4px;
}

/* Micro-interaction au hover */
.chat-bubble {
    transition: transform var(--chat-transition-fast), box-shadow var(--chat-transition-fast);
}

.chat-message.user .chat-bubble:hover {
    transform: translateX(-3px);
    box-shadow: 0 6px 20px rgba(0, 240, 255, 0.3);
}

.chat-message.assistant .chat-bubble:hover {
    transform: translateX(3px);
    border-color: rgba(0, 240, 255, 0.2);
}

/* ============================================
   INDICATEUR DE FRAPPE
   ============================================ */
.chat-message.typing .chat-bubble {
    display: flex;
    gap: 6px;
    padding: 18px 24px;
    background: rgba(255, 255, 255, 0.05);
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: var(--chat-gradient-ai);
    border-radius: 50%;
    animation: chatTypingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingBounce {
    0%, 60%, 100% { 
        transform: translateY(0);
        opacity: 0.5;
    }
    30% { 
        transform: translateY(-12px);
        opacity: 1;
    }
}

/* ============================================
   ZONE DE SAISIE
   ============================================ */
#chat-input-container {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 12px;
    background: rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 2;
}

#chat-input {
    flex: 1;
    padding: 16px 20px;
    border-radius: var(--chat-input-radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--chat-text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: all var(--chat-transition-normal);
}

#chat-input:focus {
    border-color: var(--chat-primary);
    background: rgba(0, 240, 255, 0.05);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.1), inset 0 0 20px rgba(0, 240, 255, 0.02);
}

#chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* ============================================
   BOUTON ENVOYER
   ============================================ */
#chat-send {
    width: 52px;
    height: 52px;
    border-radius: var(--chat-input-radius);
    background: var(--chat-gradient-ai);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chat-dark);
    transition: all var(--chat-transition-normal);
    position: relative;
    overflow: hidden;
}

/* Effet shimmer (comme le site) */
#chat-send::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

#chat-send:hover::before {
    transform: translateX(100%);
}

#chat-send:hover {
    transform: translateY(-3px);
    box-shadow: var(--chat-shadow-glow-strong);
}

#chat-send:active {
    transform: translateY(0) scale(0.95);
}

#chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#chat-send:disabled::before {
    display: none;
}

#chat-send svg {
    width: 22px;
    height: 22px;
    transition: transform var(--chat-transition-fast);
}

#chat-send:hover svg {
    transform: translateX(3px) rotate(-15deg);
}

/* ============================================
   ANIMATIONS D'ENTRÉE
   ============================================ */
@keyframes chatFadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chatSlideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   RESPONSIVE - TABLETTE
   ============================================ */
@media (max-width: 768px) {
    :root {
        --chat-width: 360px;
        --chat-height: 500px;
        --chat-bottom: 16px;
        --chat-right: 16px;
        --chat-toggle-size: 56px;
    }
    
    #chat-header {
        padding: 16px;
    }
    
    #chat-avatar {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }
    
    #chat-title {
        font-size: 1rem;
    }
    
    #chat-messages {
        padding: 16px;
        gap: 14px;
    }
    
    .chat-bubble {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
    
    #chat-input-container {
        padding: 16px;
    }
    
    #chat-input {
        padding: 14px 16px;
    }
    
    #chat-send {
        width: 48px;
        height: 48px;
    }
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */
@media (max-width: 480px) {
    :root {
        --chat-bottom: 12px;
        --chat-right: 12px;
        --chat-toggle-size: 52px;
        --chat-border-radius: 20px;
    }
    
    #chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 70px);
        max-height: calc(100vh - 70px);
        border-radius: var(--chat-border-radius) var(--chat-border-radius) 0 0;
    }
    
    #chat-window.open {
        animation: chatWindowOpenMobile var(--chat-transition-normal);
    }
    
    @keyframes chatWindowOpenMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    #chat-toggle svg {
        width: 24px;
        height: 24px;
    }
    
    #chat-header {
        padding: 14px 16px;
    }
    
    #chat-avatar {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }
    
    #chat-avatar::before {
        display: none;
    }
    
    #chat-close {
        width: 32px;
        height: 32px;
    }
    
    #chat-messages {
        padding: 14px;
        gap: 12px;
    }
    
    .chat-message {
        max-width: 90%;
    }
    
    .chat-bubble {
        padding: 12px 14px;
        font-size: 0.9rem;
        border-radius: 16px 16px 16px 4px;
    }
    
    .chat-message.user .chat-bubble {
        border-radius: 16px 16px 4px 16px;
    }
    
    #chat-input-container {
        padding: 12px 14px 20px;
    }
    
    #chat-input {
        padding: 14px;
        font-size: 16px; /* Évite le zoom sur iOS */
    }
    
    #chat-send {
        width: 48px;
        height: 48px;
        min-width: 48px;
    }
}

/* ============================================
   THÈME CLAIR (optionnel)
   Ajouter class="chat-light" au #chat-widget
   ============================================ */
#chat-widget.chat-light {
    --chat-dark: #ffffff;
    --chat-dark-lighter: #f5f5f5;
    --chat-dark-card: rgba(255, 255, 255, 0.95);
    --chat-text: #1a1a25;
    --chat-text-muted: #666666;
}

#chat-widget.chat-light #chat-window {
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.15);
}

#chat-widget.chat-light .chat-message.assistant .chat-bubble {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--chat-text);
}

#chat-widget.chat-light #chat-input {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--chat-text);
}

#chat-widget.chat-light #chat-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* ============================================
   PRÉFÉRENCE MOUVEMENT RÉDUIT
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   ÉTAT DE CHARGEMENT GLOBAL
   ============================================ */
#chat-widget.loading #chat-send {
    pointer-events: none;
}

#chat-widget.loading #chat-input {
    opacity: 0.7;
}

/* ============================================
   FIX SCROLL HORIZONTAL MOBILE (Android/iOS)
   ============================================ */
@media (max-width: 480px) {
    /* Empêche le débordement horizontal de la page */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        position: relative;
    }
    
    /* S'assure que le widget reste dans la viewport */
    #chat-widget {
        right: 12px !important;
        left: auto !important;
        max-width: calc(100vw - 24px);
    }
    
    #chat-toggle {
        position: relative;
        z-index: 9999;
    }
}

/* Cacher le bouton toggle quand le chat est ouvert sur mobile */
@media (max-width: 480px) {
    #chat-window.open ~ #chat-toggle,
    #chat-widget.chat-open #chat-toggle {
        display: none !important;
    }
}

/* Fix iPhone - cacher toggle quand chat ouvert */
@media (max-width: 768px) {
    #chat-widget.chat-open #chat-toggle {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }
}
