/**
 * LDDE AI Assistant - Widget Styles v2
 * Interface moderne avec support avatar et personnalisation
 */

/* Variables CSS - héritées de la config */
.ldde-chat-widget {
    --ldde-primary: #0066cc;
    --ldde-secondary: #004499;
    --ldde-text: #333333;
    --ldde-bg: #ffffff;
    --ldde-gray-light: #f5f5f7;
    --ldde-gray-medium: #e0e0e0;
    --ldde-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --ldde-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.2);
    --ldde-radius: 16px;
    --ldde-radius-sm: 8px;
    --ldde-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --ldde-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Reset */
.ldde-chat-widget,
.ldde-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--ldde-font);
}

/* ============================================
   WIDGET CONTAINER
   ============================================ */
.ldde-chat-widget {
    position: fixed;
    z-index: 999999;
    font-size: 16px;
    line-height: 1.5;
}

/* Position variants */
.ldde-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.ldde-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* ============================================
   CHAT BUBBLE (Trigger button)
   ============================================ */
.ldde-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ldde-primary) 0%, var(--ldde-secondary) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ldde-shadow);
    transition: var(--ldde-transition);
    position: relative;
    color: white;
}

.ldde-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: var(--ldde-shadow-hover);
}

.ldde-chat-bubble:active {
    transform: scale(0.95);
}

.ldde-chat-bubble svg {
    width: 28px;
    height: 28px;
}

/* Icônes de la bulle */
.ldde-bubble-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ldde-bubble-icon-close {
    display: none;
}

.ldde-chat-open .ldde-bubble-icon-chat {
    display: none;
}

.ldde-chat-open .ldde-bubble-icon-close {
    display: flex;
}

.ldde-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ff3b30;
    color: white;
    font-size: 12px;
    font-weight: 600;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: ldde-pulse 2s infinite;
}

@keyframes ldde-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ============================================
   CHAT WINDOW
   ============================================ */
.ldde-chat-window {
    position: absolute;
    bottom: 70px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 100px);
    background: var(--ldde-bg);
    border-radius: var(--ldde-radius);
    box-shadow: var(--ldde-shadow-hover);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--ldde-transition);
}

/* Position variants for window */
.ldde-position-bottom-right .ldde-chat-window {
    right: 0;
}

.ldde-position-bottom-left .ldde-chat-window {
    left: 0;
}

/* Open state */
.ldde-chat-open .ldde-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ============================================
   CHAT HEADER
   ============================================ */
.ldde-chat-header {
    background: linear-gradient(135deg, var(--ldde-primary) 0%, var(--ldde-secondary) 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ldde-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ldde-header-avatar,
.ldde-header-avatar-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ldde-header-avatar {
    object-fit: cover;
}

.ldde-header-avatar-placeholder svg {
    width: 24px;
    height: 24px;
    opacity: 0.8;
}

.ldde-header-text {
    display: flex;
    flex-direction: column;
}

.ldde-header-name {
    font-size: 17px;
    font-weight: 600;
}

.ldde-header-status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ldde-status-dot {
    width: 8px;
    height: 8px;
    background: #34c759;
    border-radius: 50%;
    animation: ldde-status-pulse 2s infinite;
}

@keyframes ldde-status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ldde-chat-header-actions {
    display: flex;
    gap: 4px;
}

.ldde-header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: var(--ldde-transition);
}

.ldde-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ldde-header-btn svg {
    width: 18px;
    height: 18px;
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */
.ldde-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--ldde-gray-light);
}

/* Scrollbar */
.ldde-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ldde-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ldde-chat-messages::-webkit-scrollbar-thumb {
    background: var(--ldde-gray-medium);
    border-radius: 3px;
}

/* ============================================
   MESSAGES
   ============================================ */
.ldde-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: ldde-message-in 0.3s ease-out;
}

@keyframes ldde-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ldde-message-bot {
    align-self: flex-start;
}

.ldde-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ldde-message-avatar,
.ldde-avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--ldde-gray-medium);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ldde-message-avatar {
    object-fit: cover;
}

.ldde-avatar-placeholder svg {
    width: 20px;
    height: 20px;
    color: var(--ldde-text);
    opacity: 0.5;
}

.ldde-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ldde-message-bubble {
    padding: 12px 16px;
    border-radius: var(--ldde-radius);
    line-height: 1.5;
    word-wrap: break-word;
}

.ldde-message-bot .ldde-message-bubble {
    background: var(--ldde-bg);
    color: var(--ldde-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ldde-message-user .ldde-message-bubble {
    background: linear-gradient(135deg, var(--ldde-primary) 0%, var(--ldde-secondary) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ldde-message-time {
    font-size: 11px;
    color: #999;
    padding: 0 4px;
}

/* Markdown styles in messages */
.ldde-message-bubble ol,
.ldde-message-bubble ul {
    margin: 8px 0;
    padding-left: 20px;
}

.ldde-message-bubble ol {
    list-style-type: decimal;
}

.ldde-message-bubble ul {
    list-style-type: disc;
}

.ldde-message-bubble li {
    margin: 4px 0;
    line-height: 1.4;
}

.ldde-message-bubble strong {
    font-weight: 600;
}

.ldde-message-bubble em {
    font-style: italic;
}

/* Links in messages */
.ldde-message-bubble a {
    color: var(--ldde-primary);
    text-decoration: underline;
    font-weight: 500;
}

.ldde-message-bubble a:hover {
    text-decoration: underline;
    opacity: 0.8;
}

/* Phone links */
.ldde-phone-link {
    color: var(--ldde-primary);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}

.ldde-phone-link:hover {
    text-decoration: underline;
}

/* Contact action buttons in messages */
.ldde-contact-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.ldde-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--ldde-radius-sm);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: var(--ldde-transition);
}

.ldde-btn-callback {
    background: var(--ldde-primary);
    color: white;
}

.ldde-btn-callback:hover {
    background: var(--ldde-secondary);
}

.ldde-btn-phone {
    background: var(--ldde-bg);
    color: var(--ldde-primary);
    border: 1px solid var(--ldde-primary);
}

.ldde-btn-phone:hover {
    background: var(--ldde-primary);
    color: white;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.ldde-typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px 16px;
    background: var(--ldde-gray-light);
}

.ldde-typing-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--ldde-gray-medium);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ldde-typing-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ldde-typing-avatar svg {
    width: 20px;
    height: 20px;
    color: var(--ldde-text);
    opacity: 0.5;
}

.ldde-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ldde-bg);
    border-radius: var(--ldde-radius);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ldde-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--ldde-gray-medium);
    border-radius: 50%;
    animation: ldde-typing 1.4s infinite;
}

.ldde-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ldde-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ldde-typing {
    0%, 60%, 100% { 
        transform: translateY(0);
        background: var(--ldde-gray-medium);
    }
    30% { 
        transform: translateY(-6px);
        background: var(--ldde-primary);
    }
}

/* ============================================
   INPUT AREA
   ============================================ */
.ldde-chat-input-area {
    padding: 12px 16px;
    background: var(--ldde-bg);
    border-top: 1px solid var(--ldde-gray-medium);
}

.ldde-chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ldde-chat-form textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--ldde-gray-medium);
    border-radius: 20px;
    font-size: 15px;
    outline: none;
    transition: var(--ldde-transition);
    background: var(--ldde-gray-light);
    resize: none;
    min-height: 44px;
    max-height: 66px;
    line-height: 1.4;
    font-family: inherit;
    overflow-y: auto;
}

.ldde-chat-form textarea:focus {
    border-color: var(--ldde-primary);
    background: var(--ldde-bg);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.ldde-chat-form textarea::placeholder {
    color: #999;
}

#ldde-chat-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: linear-gradient(135deg, var(--ldde-primary) 0%, var(--ldde-secondary) 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: var(--ldde-transition);
    flex-shrink: 0;
    padding: 0;
}

#ldde-chat-send svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

#ldde-chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

#ldde-chat-send:active {
    transform: scale(0.95);
}

.ldde-chat-powered {
    text-align: center;
    font-size: 11px;
    color: #999;
    margin-top: 8px;
}

.ldde-chat-powered strong {
    color: var(--ldde-text);
}

/* ============================================
   LEAD FORM OVERLAY
   ============================================ */
.ldde-lead-form-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10;
    animation: ldde-fade-in 0.3s ease;
}

@keyframes ldde-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ldde-lead-form-container {
    background: var(--ldde-bg);
    border-radius: var(--ldde-radius);
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    animation: ldde-slide-up 0.3s ease;
}

@keyframes ldde-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ldde-lead-form-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--ldde-gray-light);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ldde-text);
    transition: var(--ldde-transition);
}

.ldde-lead-form-close:hover {
    background: var(--ldde-gray-medium);
}

.ldde-lead-form-close svg {
    width: 16px;
    height: 16px;
}

.ldde-lead-form-header {
    text-align: center;
    margin-bottom: 20px;
}

.ldde-lead-form-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--ldde-text);
    margin-bottom: 8px;
}

.ldde-lead-form-header p {
    font-size: 14px;
    color: #666;
}

.ldde-lead-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ldde-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.ldde-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ldde-form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ldde-text);
}

.ldde-form-group input[type="text"],
.ldde-form-group input[type="tel"],
.ldde-form-group input[type="email"] {
    padding: 12px 14px;
    border: 1px solid var(--ldde-gray-medium);
    border-radius: var(--ldde-radius-sm);
    font-size: 15px;
    outline: none;
    transition: var(--ldde-transition);
}

.ldde-form-group input:focus {
    border-color: var(--ldde-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.ldde-form-checkboxes label:first-child {
    margin-bottom: 4px;
}

.ldde-checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.ldde-checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    padding: 8px 10px;
    background: var(--ldde-gray-light);
    border-radius: var(--ldde-radius-sm);
    transition: var(--ldde-transition);
}

.ldde-checkbox-grid label:hover {
    background: var(--ldde-gray-medium);
}

.ldde-checkbox-grid input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--ldde-primary);
}

.ldde-lead-submit {
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--ldde-primary) 0%, var(--ldde-secondary) 100%);
    color: white;
    border: none;
    border-radius: var(--ldde-radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--ldde-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.ldde-lead-submit:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 102, 204, 0.3);
}

.ldde-lead-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.ldde-spinner {
    width: 20px;
    height: 20px;
    animation: ldde-spin 1s linear infinite;
}

@keyframes ldde-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============================================
   STYLE VARIANTS
   ============================================ */

/* Classic style */
.ldde-style-classic {
    --ldde-radius: 8px;
    --ldde-radius-sm: 4px;
}

.ldde-style-classic .ldde-chat-bubble {
    border-radius: 8px;
}

.ldde-style-classic .ldde-message-bubble {
    border-radius: 8px;
}

.ldde-style-classic .ldde-message-bot .ldde-message-bubble {
    border-bottom-left-radius: 2px;
}

.ldde-style-classic .ldde-message-user .ldde-message-bubble {
    border-bottom-right-radius: 2px;
}

/* Minimal style */
.ldde-style-minimal {
    --ldde-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --ldde-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.ldde-style-minimal .ldde-chat-header {
    background: var(--ldde-bg);
    color: var(--ldde-text);
    border-bottom: 1px solid var(--ldde-gray-medium);
}

.ldde-style-minimal .ldde-header-btn {
    background: var(--ldde-gray-light);
    color: var(--ldde-text);
}

.ldde-style-minimal .ldde-header-btn:hover {
    background: var(--ldde-gray-medium);
}

.ldde-style-minimal .ldde-header-avatar-placeholder {
    background: var(--ldde-gray-light);
    border-color: var(--ldde-gray-medium);
}

.ldde-style-minimal .ldde-status-dot {
    border: 1px solid var(--ldde-gray-medium);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    .ldde-chat-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
    }
    
    .ldde-chat-bubble {
        position: fixed;
        bottom: 16px;
        right: 16px;
    }
    
    .ldde-chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .ldde-form-row {
        grid-template-columns: 1fr;
    }
    
    .ldde-checkbox-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   DARK MODE SUPPORT (optional)
   ============================================ */
@media (prefers-color-scheme: dark) {
    .ldde-chat-widget.ldde-auto-theme {
        --ldde-bg: #1c1c1e;
        --ldde-text: #f2f2f7;
        --ldde-gray-light: #2c2c2e;
        --ldde-gray-medium: #3a3a3c;
    }
}
