/* ============================================
   FINANCIAL CHATBOT - FUTURISTIC 3D STYLES
   Ultra-Premium Design (CORRECTED)
   ============================================ */

:root {
    /* Futuristic Color Palette */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --danger-gradient: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    
    /* Neon Glow */
    --neon-blue: #00d9ff;
    --neon-purple: #b74dff;
    --neon-pink: #ff4da6;
    --neon-green: #39ff14;
    
    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    
    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 750ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    
    /* Z-Index */
    --z-fixed: 999998;
    --z-modal: 999999;
}

/* ============================================
   CHATBOT CONTAINER
   ============================================ */

.chatbot-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: var(--z-fixed);
    font-family: var(--font-primary);
    pointer-events: none;
}

.chatbot-container > * {
    pointer-events: auto;
}

.chatbot-widget {
    display: none;
    flex-direction: column;
    width: 450px; /* ✅ Légèrement agrandi (420px → 450px) */
    height: 750px; /* ✅ Hauteur augmentée (650px → 750px) */
    max-height: 90vh; /* ✅ Respect de la taille de la page */
    background: var(--glass-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset,
        0 20px 60px rgba(102, 126, 234, 0.3);
    transform: translateZ(0);
    will-change: transform, box-shadow;
    transition: all var(--transition-smooth);
    position: relative;
}

.chatbot-widget:not(.hidden) {
    display: flex !important;
}

.chatbot-widget.chatbot-open {
    display: flex !important;
}

.chatbot-widget::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--neon-blue),
        var(--neon-purple),
        var(--neon-pink),
        transparent
    );
    background-size: 200% 100%;
    animation: neon-scan 3s linear infinite;
    z-index: 2;
}

@keyframes neon-scan {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

.chatbot-widget:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 
        0 12px 48px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset,
        0 24px 80px rgba(102, 126, 234, 0.4),
        0 0 60px rgba(0, 217, 255, 0.3);
}

/* ============================================
   CHATBOT HEADER
   ============================================ */

.chatbot-header {
    background: linear-gradient(
        135deg,
        rgba(102, 126, 234, 0.2) 0%,
        rgba(118, 75, 162, 0.2) 100%
    );
    backdrop-filter: blur(20px);
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
    flex-shrink: 0; /* ✅ Empêcher le header de rétrécir */
}

.chatbot-header::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300%;
    height: 300%;
    background: radial-gradient(
        circle,
        rgba(255, 255, 255, 0.1) 0%,
        transparent 70%
    );
    transform: translate(-50%, -50%);
    animation: pulse-glow 4s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.1); }
}

.chatbot-header-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    position: relative;
    z-index: 1;
}

.chatbot-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 
        0 4px 12px rgba(102, 126, 234, 0.4),
        0 0 20px rgba(102, 126, 234, 0.3) inset;
    position: relative;
    overflow: hidden;
    animation: float-avatar 3s ease-in-out infinite;
}

@keyframes float-avatar {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-4px) rotate(5deg); }
}

.chatbot-title-section {
    flex: 1;
}

.chatbot-title {
    font-size: 1.125rem;
    font-weight: 700;
    background: linear-gradient(135deg, #00d9ff 0%, #b74dff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    /* ✅ CORRECTION: Online en cyan au lieu de blanc */
    color: #00d9ff;
    font-weight: 500;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--neon-green);
    box-shadow: 
        0 0 10px var(--neon-green),
        0 0 20px var(--neon-green);
    animation: pulse-indicator 2s ease-in-out infinite;
}

@keyframes pulse-indicator {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

.chatbot-header-actions {
    display: flex;
    gap: var(--spacing-sm);
    position: relative;
    z-index: 10;
}

.chatbot-header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    pointer-events: auto !important;
    z-index: 100;
}

.chatbot-header-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width var(--transition-base), height var(--transition-base);
}

.chatbot-header-btn:hover::before {
    width: 100%;
    height: 100%;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chatbot-header-btn:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */

.chatbot-messages {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    position: relative;
    background: linear-gradient(
        180deg,
        rgba(10, 10, 26, 0.5) 0%,
        rgba(10, 10, 26, 0.8) 100%
    );
    /* ✅ Utiliser l'espace disponible */
    min-height: 0;
}

.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--neon-blue), var(--neon-purple));
    border-radius: var(--radius-full);
    box-shadow: 0 0 10px rgba(0, 217, 255, 0.5);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--neon-purple), var(--neon-pink));
    box-shadow: 0 0 15px rgba(183, 77, 255, 0.7);
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */

.message {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    animation: message-slide-in var(--transition-smooth) ease-out;
}

@keyframes message-slide-in {
    0% {
        opacity: 0;
        transform: translateX(-30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.message.user-message {
    flex-direction: row-reverse;
    animation-name: message-slide-in-right;
}

@keyframes message-slide-in-right {
    0% {
        opacity: 0;
        transform: translateX(30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.message-avatar.bot-avatar {
    background: var(--primary-gradient);
    box-shadow: 
        0 4px 12px rgba(102, 126, 234, 0.4),
        0 0 20px rgba(102, 126, 234, 0.2);
}

.message-avatar.user-avatar {
    background: var(--secondary-gradient);
    box-shadow: 
        0 4px 12px rgba(240, 147, 251, 0.4),
        0 0 20px rgba(240, 147, 251, 0.2);
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    transition: all var(--transition-base);
    /* ✅ CORRECTION: Empêcher le débordement horizontal */
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.message.bot-message .message-bubble {
    background: linear-gradient(
        135deg,
        rgba(102, 126, 234, 0.15) 0%,
        rgba(118, 75, 162, 0.15) 100%
    );
    border-top-left-radius: 4px;
}

.message.user-message .message-bubble {
    background: linear-gradient(
        135deg,
        rgba(240, 147, 251, 0.15) 0%,
        rgba(245, 87, 108, 0.15) 100%
    );
    border-top-right-radius: 4px;
}

.message-text {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.95);
    margin: 0;
    /* ✅ CORRECTION: Gérer les longs textes et les barres horizontales */
    overflow-x: auto;
    max-width: 100%;
}

/* ✅ CORRECTION: Barres horizontales limitées à la zone de texte */
.message-text hr,
.message-text table,
.message-text pre,
.message-text code {
    max-width: 100%;
    overflow-x: auto;
}

.message-text hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: var(--spacing-md) 0;
    /* ✅ CORRECTION CRITIQUE: Limiter la largeur */
    width: 100%;
    max-width: 100%;
}

.message-text strong {
    color: var(--neon-blue);
    font-weight: 600;
}

.message-text em {
    color: var(--neon-pink);
    font-style: normal;
}

.message-text table {
    font-size: 0.875rem;
    border-collapse: collapse;
    margin: var(--spacing-sm) 0;
}

.message-text th,
.message-text td {
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message-time {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: var(--spacing-xs);
    display: block;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: var(--spacing-md);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--neon-blue);
    animation: typing-bounce 1.4s ease-in-out infinite;
    box-shadow: 0 0 10px var(--neon-blue);
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
    background: var(--neon-purple);
    box-shadow: 0 0 10px var(--neon-purple);
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
    background: var(--neon-pink);
    box-shadow: 0 0 10px var(--neon-pink);
}

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* ============================================
   SUGGESTIONS
   ============================================ */

.chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    padding: 0 var(--spacing-lg) var(--spacing-md);
    animation: suggestions-slide-up var(--transition-smooth) ease-out;
    flex-shrink: 0; /* ✅ Empêcher de rétrécir */
}

@keyframes suggestions-slide-up {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.suggestion-chip {
    padding: var(--spacing-sm) var(--spacing-md);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    color: #00d9ff;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    font-weight: 500;
}

.suggestion-chip::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    transition: left var(--transition-base);
}

.suggestion-chip:hover::before {
    left: 100%;
}

.suggestion-chip:hover {
    background: rgba(102, 126, 234, 0.3);
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 
        0 4px 12px rgba(102, 126, 234, 0.4),
        0 0 20px rgba(102, 126, 234, 0.2);
    color: #ffffff;
}

.suggestion-chip:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================
   INPUT AREA
   ============================================ */

.chatbot-input-area {
    padding: var(--spacing-lg);
    background: linear-gradient(
        180deg,
        rgba(10, 10, 26, 0.8) 0%,
        rgba(10, 10, 26, 0.95) 100%
    );
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    position: relative;
    flex-shrink: 0; /* ✅ Empêcher de rétrécir */
}

.chatbot-input-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--neon-blue),
        var(--neon-purple),
        transparent
    );
}

.chatbot-input-container {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-end;
}

.chatbot-input-wrapper {
    flex: 1;
    position: relative;
}

.chatbot-input {
    width: 100%;
    padding: var(--spacing-md) var(--spacing-lg);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9375rem;
    font-family: var(--font-primary);
    resize: none;
    /* ✅ CORRECTION: Hauteur fixe sans scroll visible */
    height: 48px;
    min-height: 48px;
    max-height: 48px;
    overflow: hidden; /* ✅ Masquer le scroll */
    transition: all var(--transition-base);
    outline: none;
    line-height: 1.5;
}

.chatbot-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chatbot-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--neon-blue);
    box-shadow: 
        0 0 0 3px rgba(0, 217, 255, 0.2),
        0 4px 16px rgba(0, 217, 255, 0.3),
        0 0 30px rgba(0, 217, 255, 0.1);
}

.chatbot-send-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--primary-gradient);
    border-radius: var(--radius-md);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    box-shadow: 
        0 4px 12px rgba(102, 126, 234, 0.4),
        0 0 20px rgba(102, 126, 234, 0.2);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.chatbot-send-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width var(--transition-fast), height var(--transition-fast);
}

.chatbot-send-btn:hover::before {
    width: 120%;
    height: 120%;
}

.chatbot-send-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 
        0 6px 16px rgba(102, 126, 234, 0.5),
        0 0 30px rgba(102, 126, 234, 0.3);
}

.chatbot-send-btn:active {
    transform: translateY(0) scale(0.95);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   TOGGLE BUTTON (FLOATING)
   ============================================ */

.chatbot-toggle-btn {
    width: 64px;
    height: 64px;
    border: none;
    background: var(--primary-gradient);
    border-radius: 50%;
    color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 24px rgba(102, 126, 234, 0.4),
        0 0 40px rgba(102, 126, 234, 0.3);
    transition: all var(--transition-base);
    animation: float-fab 3s ease-in-out infinite;
    position: relative;
    overflow: hidden;
    pointer-events: auto !important;
    z-index: var(--z-modal);
}

@keyframes float-fab {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.05); }
}

.chatbot-toggle-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    transform: rotate(45deg);
    animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

.chatbot-toggle-btn:hover {
    transform: translateY(-4px) scale(1.1);
    box-shadow: 
        0 12px 32px rgba(102, 126, 234, 0.5),
        0 0 60px rgba(102, 126, 234, 0.4);
}

.chatbot-toggle-btn:active {
    transform: translateY(-2px) scale(1.05);
}

/* ============================================
   CHART CONTAINER
   ============================================ */

.chart-container {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-lg);
    background: rgba(10, 10, 26, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.chart-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--neon-blue),
        var(--neon-purple),
        var(--neon-pink)
    );
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.chart-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    letter-spacing: 0.02em;
}

.chart-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.chart-btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-base);
}

.chart-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-color: var(--neon-blue);
    box-shadow: 0 0 10px rgba(0, 217, 255, 0.3);
}

.chart-canvas-wrapper {
    position: relative;
    height: 300px;
}

/* ============================================
   UTILITIES
   ============================================ */

.hidden {
    display: none !important;
}

.fade-in {
    animation: fade-in var(--transition-base) ease-in;
}

@keyframes fade-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.bounce-in {
    animation: bounce-in var(--transition-smooth) cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounce-in {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .chatbot-container {
        bottom: 0;
        right: 0;
        left: 0;
    }
    
    .chatbot-widget {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .message-content {
        max-width: 85%;
    }
}