/* ========================================
   CHATBOT WIDGET - Tableau des Îles
   Direction Artistique: Vert
   ======================================== */

:root {
    --chatbot-primary: #2a7492;
    --chatbot-primary-dark: #1f5a73;
    --chatbot-secondary: #06d6a0;
    --chatbot-accent: #05b889;
    --chatbot-bg: #ffffff;
    --chatbot-border: rgba(6, 214, 160, 0.15);
    --chatbot-text: #000000;
    --chatbot-text-light: #666666;
    --chatbot-bot-bg: #f8f9fa;
    --chatbot-user-bg: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    --chatbot-user-text: #ffffff;
    --chatbot-shadow: 0 8px 32px rgba(6, 214, 160, 0.2);
    --chatbot-radius: 16px;
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Empêcher les événements pointer sur le contenu du bouton */
.chatbot-toggle svg,
.chatbot-toggle svg *,
.chatbot-toggle .unread-badge {
    pointer-events: none;
}

/* Conteneur principal */
#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Bouton flottant avec gradient vert */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    position: relative;
    z-index: 100;
    padding: 0;
    font-size: 26px;
}

.chatbot-toggle:hover {
    background: linear-gradient(135deg, #1f5a73 0%, #05b889 100%);
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(6, 214, 160, 0.4);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

/* Badge de messages non lus avec gradient vert */
.unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    border: 3px solid white;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(231, 76, 60, 0.5);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 6px 20px rgba(231, 76, 60, 0.7);
        transform: scale(1.05);
    }
}

/* Fenêtre du chatbot avec bordure subtile */
.chatbot-window {
    position: absolute;
    bottom: 90px;
    right: 0;
    width: 420px;
    height: 600px;
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    border: 2px solid rgba(6, 214, 160, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
    z-index: 99;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

.chatbot-window.closing {
    animation: slideDown 0.3s ease-out forwards;
}

/* En-tête du chatbot avec gradient vert */
.chatbot-header {
    background: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    color: white;
    padding: 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: none;
    position: relative;
    overflow: hidden;
}

/* Effet subtil d'éclat sur le header */
.chatbot-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    opacity: 0.5;
}

.chatbot-title {
    position: relative;
    z-index: 2;
}

.chatbot-title h3 {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.chatbot-title p {
    margin: 6px 0 0 0;
    font-size: 13px;
    opacity: 0.95;
    font-weight: 400;
}

/* Groupe d'actions du header (nouvelle conversation + fermer) */
.chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 2;
}

.chatbot-close,
.chatbot-new-conv {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    padding: 0;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Survol « nouvelle conversation » : pas de rotation, juste un léger zoom */
.chatbot-new-conv:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Zone de messages avec fond subtil - Optimisé pour visibilité mobile */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #ffffff;
}

/* Fond dégradé désactivé sur mobile pour meilleure lisibilité */
@media (min-width: 768px) {
    .chatbot-messages {
        background: linear-gradient(to bottom, #fafafa 0%, #f5f5f5 100%);
    }
}

/* Barre de scroll personnalisée avec couleur verte */
.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: rgba(6, 214, 160, 0.05);
    border-radius: 10px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #2a7492 0%, #06d6a0 100%);
    border-radius: 10px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #1f5a73 0%, #05b889 100%);
}

/* Messages */
.chatbot-message {
    display: flex;
    animation: fadeIn 0.3s ease-out;
    margin-bottom: 8px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Messages du bot avec bordure verte subtile */
.chatbot-message.bot-message {
    justify-content: flex-start;
}

.chatbot-message.bot-message .message-content {
    background: var(--chatbot-bot-bg);
    color: #000000;
    border-radius: var(--chatbot-radius);
    border: 2px solid var(--chatbot-border);
    max-width: 85%;
    box-shadow: 0 2px 8px rgba(6, 214, 160, 0.08);
}

/* Messages de l'utilisateur avec gradient vert */
.chatbot-message.user-message {
    justify-content: flex-end;
}

.chatbot-message.user-message .message-content {
    background: var(--chatbot-user-bg);
    color: var(--chatbot-user-text);
    border-radius: var(--chatbot-radius);
    max-width: 85%;
    box-shadow: 0 4px 12px rgba(6, 214, 160, 0.2);
}

/* Contenu du message - Texte optimisé pour visibilité */
.message-content {
    padding: 12px 16px;
    word-wrap: break-word;
    line-height: 1.5;
    color: #000000;
    font-weight: 500;
}

/* Amélioration contraste mobile */
@media (max-width: 767px) {
    .chatbot-message.bot-message .message-content {
        font-weight: 600; /* couleur héritée : noir (cf. règle unique plus bas) */
    }

    .chatbot-message.user-message .message-content {
        font-weight: 600;
    }
}

.message-content p {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: inherit;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Messages de bienvenue et messages système */
.chatbot-message.bot-message .message-content * {
    color: #000000 !important;
}

.message-content strong {
    font-weight: 600;
}

.message-content a {
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.message-content a:hover {
    opacity: 0.8;
}

/* Suggestions */
.suggestions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.suggestion-btn {
    background: white;
    border: 2px solid var(--chatbot-border);
    color: #000000 !important;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chatbot-transition);
    text-align: center;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(6, 214, 160, 0.08);
}

.suggestion-btn:hover {
    background: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    color: white !important;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(6, 214, 160, 0.3);
}

.suggestion-btn:active {
    transform: translateY(0);
}

/* Zone d'entrée avec bordure subtile */
.chatbot-input-area {
    padding: 16px 18px;
    background: var(--chatbot-bg);
    border-top: 2px solid var(--chatbot-border);
    box-shadow: 0 -4px 12px rgba(6, 214, 160, 0.05);
}

.chatbot-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    border: 2px solid var(--chatbot-border);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    color: var(--chatbot-text);
    background: white;
    transition: var(--chatbot-transition);
    outline: none;
    font-family: inherit;
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 4px rgba(6, 214, 160, 0.1);
}

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

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 4px 12px rgba(6, 214, 160, 0.25);
}

.chatbot-send:hover:not(:disabled) {
    background: linear-gradient(135deg, #1f5a73 0%, #05b889 100%);
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(6, 214, 160, 0.35);
}

.chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Helpers */
.input-helpers {
    display: flex;
    gap: 6px;
    padding: 0 4px;
}

.helper-btn {
    background: none;
    border: none;
    color: var(--chatbot-text-light);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.helper-btn:hover {
    background: rgba(6, 214, 160, 0.1);
    color: var(--chatbot-primary);
    transform: translateY(-1px);
}

/* Indicateur de saisie */
.chatbot-typing {
    display: flex;
    justify-content: flex-start;
    padding: 16px;
    gap: 5px;
}

.chatbot-typing span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2a7492 0%, #06d6a0 100%);
    animation: typing 1.4s infinite;
    box-shadow: 0 2px 4px rgba(6, 214, 160, 0.3);
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.4;
        transform: translateY(0) scale(1);
    }
    30% {
        opacity: 1;
        transform: translateY(-12px) scale(1.1);
    }
}

/* Erreur */
.chatbot-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    border-radius: var(--chatbot-radius);
    padding: 12px 16px;
    margin: 8px 0;
    font-size: 13px;
}

/* Mode responsive */
@media (max-width: 767px) {
    #chatbot-widget {
        bottom: 10px;
        right: 10px;
    }

    .chatbot-window {
        position: fixed;
        bottom: 76px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: calc(100% - 20px);
        height: 70vh;
        max-height: 500px;
    }

    .chatbot-toggle {
        width: 50px;
        height: 50px;
    }

    .suggestions-grid {
        grid-template-columns: 1fr;
    }

    .chatbot-message.bot-message .message-content,
    .chatbot-message.user-message .message-content {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .chatbot-window {
        bottom: 70px;
        height: 60vh;
        border-radius: 12px 12px 0 0;
    }

    .chatbot-header {
        padding: 16px;
    }

    .chatbot-title h3 {
        font-size: 16px;
    }

    .chatbot-title p {
        font-size: 11px;
    }

    .chatbot-messages {
        padding: 12px;
        gap: 8px;
    }

    .message-content {
        padding: 10px 12px;
        font-size: 13px;
    }

    .suggestion-btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .chatbot-input {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* Thème sombre optionnel */
@media (prefers-color-scheme: dark) {
    :root {
        --chatbot-bg: #2c3e50;
        --chatbot-border: #34495e;
        --chatbot-text: #ecf0f1;
        --chatbot-text-light: #95a5a6;
        /* Bulle du bot : on garde le fond CLAIR même en dark-mode OS, pour que le
           texte reste noir et lisible (cf. demande : noir sur fond blanc). */
    }

    .chatbot-suggestion-btn {
        background: #34495e;
        color: #ecf0f1;
    }

    .suggestion-btn:hover {
        background: var(--chatbot-primary);
    }

    .chatbot-input {
        background: #34495e;
        color: #ecf0f1;
    }
}

/* Animation d'entrée fluide */
.chatbot-window.fade-in {
    animation: slideUp 0.3s ease-out;
}

.chatbot-toggle.active {
    animation: spin 0.6s ease-out;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Effets de clic */
.suggestion-btn:active,
.chatbot-send:active {
    transform: scale(0.95);
}

/* Accessibilité */
.chatbot-toggle:focus,
.chatbot-close:focus,
.chatbot-send:focus,
.suggestion-btn:focus {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    #chatbot-widget {
        display: none;
    }
}

/* Bouton "Parler à un conseiller" avec bleu-turquoise */
.request-human-btn {
    background: linear-gradient(135deg, #667eea 0%, #4facfe 100%);
    color: white !important;
    border: none;
    padding: 14px 24px;
    border-radius: 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chatbot-transition);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
}

.request-human-btn:hover {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
}

.request-human-btn:active {
    transform: translateY(0);
}

.request-human-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}
