/* Page assistant isolée du thème (pas de header / Tailwind) */
html.sobery-assistant-page,
html.sobery-assistant-page body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    overflow: hidden !important;
    background-color: #f0f0f0 !important;
    box-sizing: border-box;
}

html.sobery-assistant-page body * {
    box-sizing: border-box;
}

html.sobery-assistant-page body > div.relative.flex.w-full.flex-col {
    display: block !important;
    min-height: 100% !important;
    overflow: visible !important;
}

/* Reset partiel */
#sobery-app-container {
    font-family: 'Maven Pro', sans-serif;
    background-color: #f0f0f0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    max-height: 100vh;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    overflow: hidden;
    overflow-y: hidden;
}

:root {
    --sobery-bg: #F7F0E8;
    --sobery-accent: #d98563; 
    --sobery-accent-hover: #c57452;
    --sobery-text: #3C3633;
    --sobery-white: #FFFFFF;
    --sobery-user-msg: #d98563;
    --sobery-bot-msg: #FFFFFF;
    --sobery-light-gauge: rgba(229, 217, 209, 1);
}

#sobery-chatbot-wrapper {
    width: 100%;
    max-width: 1100px;
    background-color: var(--sobery-bg);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: 80vh;
    min-height: 600px;
    max-height: 800px;
    position: relative;
    z-index: 1;
    overflow: visible;
    /* S'assurer que les tooltips peuvent dépasser */
    contain: none;
}

/* Mobile : plein écran avec gestion overflow */
@media (max-width: 768px) {
    #sobery-app-container {
        padding: 0;
        align-items: flex-start;
        min-height: 100vh;
        min-height: 100dvh; /* Hauteur dynamique pour mobile */
        max-height: 100vh;
        max-height: 100dvh;
        overflow: hidden;
        overflow-y: hidden;
    }
    
    #sobery-chatbot-wrapper {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh; /* Hauteur dynamique pour mobile */
        min-height: 100vh;
        min-height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        /* Gérer les zones sécurisées iOS */
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .chat-header {
        padding: 15px;
        flex-shrink: 0;
        /* Gérer les zones sécurisées iOS */
        padding-top: calc(15px + env(safe-area-inset-top));
        gap: 8px;
    }
    
    #chat-window {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        min-height: 0; /* Important pour que flex fonctionne correctement */
        padding-bottom: 10px; /* Espace supplémentaire en bas */
    }
    
    #chat-controls {
        padding: 15px;
        min-height: auto;
        flex-shrink: 0;
        /* Gérer les zones sécurisées iOS et s'assurer que les contrôles sont visibles */
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
        background-color: var(--sobery-white);
        position: relative;
        z-index: 1000;
    }
}

.chat-header {
    background: linear-gradient(135deg, var(--sobery-white) 0%, #fafafa 100%);
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    border-radius: 16px 16px 0 0;
}
.chat-header h2 {
    margin: 0;
    color: var(--sobery-accent);
    font-size: 1.25rem;
    letter-spacing: 1px;
    font-weight: 700;
    font-family: 'larken', serif;
}
.chat-header h2 a {
    color:#000!important;
    text-decoration: none;
    transition: opacity 0.3s ease;
}
.chat-header h2 a:hover {
    opacity: 0.8;
}
.chat-header p {
    margin: 0;
    font-size: 0.85rem;
    color: #666;
}

#chat-window {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
    z-index: 0;
}
#chat-window::-webkit-scrollbar { width: 6px; }
#chat-window::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.1); border-radius: 3px; }

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    animation: slideUp 0.3s ease-out;
    word-wrap: break-word;
}

.bot-msg {
    align-self: flex-start;
    background-color: var(--sobery-bot-msg);
    color: var(--sobery-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
}

.user-msg {
    align-self: flex-end;
    background-color: var(--sobery-user-msg);
    color: var(--sobery-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(217, 133, 99, 0.3);
}

.chat-img-preview {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
    border: 2px solid white;
}

.typing-indicator {
    align-self: flex-start;
    background-color: rgba(255,255,255,0.6);
    padding: 10px 15px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 10px;
    display: none;
}
.typing-dots span {
    display: inline-block;
    width: 5px;
    height: 5px;
    background-color: #999;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

/* --- NOUVEAU DESIGN DES INPUTS --- */
#chat-controls {
    background-color: var(--sobery-white);
    min-height: 90px;
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    border-top: 1px solid rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    position: relative;
    z-index: 1000;
    overflow: visible;
    border-radius: 0 0 16px 16px;
}

/* Desktop : empêcher le wrap des boutons */
@media (min-width: 769px) {
    #chat-controls {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    #chat-controls::-webkit-scrollbar {
        height: 4px;
    }
    
    #chat-controls::-webkit-scrollbar-thumb {
        background-color: rgba(0,0,0,0.1);
        border-radius: 2px;
    }
}

.chat-input-text {
    flex: 1;
    min-width: 200px;
    padding: 14px 20px!important;
    border: 1px solid transparent;
    background-color: #f5f5f5;
    border-radius: 30px;
    outline: none;
    font-family: 'Maven Pro', sans-serif;
    font-size: 16px;
    color: var(--sobery-text);
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
}
.chat-input-text::placeholder { color: #999; }
.chat-input-text:focus { 
    background-color: #ffffff;
    border-color: var(--sobery-accent); 
    box-shadow: 0 4px 12px rgba(217, 133, 99, 0.15);
}

.file-upload-label {
    display: inline-block;
    padding: 12px 24px;
    background-color: #fff;
    color: var(--sobery-text);
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    border: 1px solid #e0e0e0;
    font-weight: 500;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.file-upload-label:hover { 
    border-color: var(--sobery-accent);
    color: var(--sobery-accent);
}
input[type="file"] { display: none; }

.response-btn-wrapper {
    position: relative;
    display: inline-block;
    margin: 4px;
    z-index: 1001;
}

.chat-btn {
    background: transparent;
    border: 1px solid var(--sobery-accent);
    color: var(--sobery-accent);
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Maven Pro', sans-serif;
}
.chat-btn:hover, .chat-btn:active {
    background-color: var(--sobery-accent);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(217, 133, 99, 0.2);
}
.chat-btn.primary {
    background-color: var(--sobery-accent);
    color: white;
    border: none;
    padding: 14px 28px;
}
.chat-btn.primary:hover {
    background-color: var(--sobery-accent-hover);
}

.tooltip-text {
    visibility: hidden;
    width: 220px;
    background-color: #3C3633;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 10px;
    position: fixed;
    z-index: 9999999;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(5px);
    font-size: 0.85rem;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    line-height: 1.4;
    white-space: normal;
    word-wrap: break-word;
    /* Position initiale pour éviter le décalage */
    left: -9999px;
    top: -9999px;
}
.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: #3C3633 transparent transparent transparent;
}
.response-btn-wrapper:hover .tooltip-text { 
    visibility: visible; 
    opacity: 1; 
    transform: translateY(0);
}

.final-form-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 5px;
}
.final-form-input {
    padding: 14px 18px !important;
    border: 1px solid #eee;
    background-color: #fbfbfb;
    border-radius: 12px;
    font-family: 'Maven Pro', sans-serif;
    font-size: 16px;
    color: var(--sobery-text);
    width: 100%;
    box-sizing: border-box;
    transition: all 0.3s;
}
.final-form-input:focus {
    outline: none;
    border-color: var(--sobery-accent);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(217, 133, 99, 0.1);
}
.final-form-btn {
    background-color: var(--sobery-accent);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-family: 'Maven Pro', sans-serif;
    margin-top: 5px;
    box-shadow: 0 4px 10px rgba(217, 133, 99, 0.2);
}
.final-form-btn:hover { 
    background-color: var(--sobery-accent-hover);
    transform: translateY(-1px);
}
.final-form-btn:disabled { 
    background-color: #ccc; 
    cursor: not-allowed; 
    box-shadow: none;
    transform: none;
}

.error-message {
    color: #e74c3c;
    font-size: 0.85rem;
    margin-top: -8px;
    margin-bottom: 5px;
    display: none;
    padding-left: 5px;
    font-weight: 500;
}

@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

