/* ===== CHATBOT WIDGET — Digital Sphère Services ===== */

#ds-chat-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9000;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #b79a78 0%, #8a7358 100%);
    box-shadow: 0 4px 24px rgba(183,154,120,0.38), 0 1px 6px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    outline: none;
}
#ds-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 32px rgba(183,154,120,0.52), 0 2px 8px rgba(0,0,0,0.55);
}
#ds-chat-toggle svg { transition: opacity 0.18s ease, transform 0.18s ease; }
#ds-chat-toggle .icon-close { display: none; }

#ds-chat-toggle.is-open .icon-chat  { display: none; }
#ds-chat-toggle.is-open .icon-close { display: block; }

/* Badge notification */
#ds-chat-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #0a1225;
    display: none;
}
#ds-chat-badge.visible { display: block; }

/* ===== FENÊTRE ===== */
#ds-chat-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: 8999;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #060C16;
    border: 1px solid rgba(183,154,120,0.22);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(183,154,120,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.26s ease, transform 0.26s ease;
}
#ds-chat-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
#ds-chat-header {
    padding: 16px 18px;
    background: linear-gradient(135deg, #0A1225 0%, #0F1A30 100%);
    border-bottom: 1px solid rgba(183,154,120,0.18);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.ds-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #b79a78, #8a7358);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ds-chat-avatar svg { color: #060C16; }
.ds-chat-info { flex: 1; min-width: 0; }
.ds-chat-name {
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #d4c4a8;
    line-height: 1.2;
}
.ds-chat-status {
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    color: #737373;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.ds-chat-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
}

/* Messages */
#ds-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(183,154,120,0.2) transparent;
}
#ds-chat-messages::-webkit-scrollbar { width: 4px; }
#ds-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ds-chat-messages::-webkit-scrollbar-thumb { background: rgba(183,154,120,0.25); border-radius: 2px; }

/* Rangée message + horodatage */
.ds-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 88%;
}
.ds-msg-row--bot  { align-self: flex-start; align-items: flex-start; }
.ds-msg-row--user { align-self: flex-end;   align-items: flex-end; }

.ds-msg-time {
    font-family: 'Outfit', sans-serif;
    font-size: 10px;
    color: #525252;
    margin: 3px 4px 0;
}

.ds-msg {
    font-family: 'Outfit', sans-serif;
    font-size: 13.5px;
    line-height: 1.55;
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
    animation: ds-pop 0.22s ease;
}
@keyframes ds-pop {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ds-msg--bot {
    background: #0F1A30;
    border: 1px solid rgba(183,154,120,0.15);
    color: #d4d4d4;
    border-bottom-left-radius: 4px;
}
.ds-msg--user {
    background: linear-gradient(135deg, #b79a78 0%, #8a7358 100%);
    color: #060C16;
    font-weight: 500;
    border-bottom-right-radius: 4px;
}

/* ===== RENDU MARKDOWN DANS LES MESSAGES ===== */
.ds-msg p { margin: 0 0 8px; }
.ds-msg p:last-child { margin-bottom: 0; }
.ds-msg strong { color: #d4c4a8; font-weight: 600; }
.ds-msg--user strong { color: #060C16; }
.ds-msg em { font-style: italic; }
.ds-msg a {
    color: #d4c4a8;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s;
}
.ds-msg a:hover { color: #ece6dc; }
.ds-msg--user a { color: #060C16; }
.ds-msg code {
    font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
    font-size: 12px;
    background: rgba(183,154,120,0.14);
    padding: 1px 5px;
    border-radius: 4px;
}
.ds-msg .ds-h {
    font-weight: 600;
    color: #d4c4a8;
    font-size: 13.5px;
    margin: 8px 0 4px;
}
.ds-msg .ds-h:first-child { margin-top: 0; }
.ds-msg ul, .ds-msg ol { margin: 4px 0 8px; padding-left: 20px; }
.ds-msg li { margin: 2px 0; }
.ds-msg ul { list-style: disc; }
.ds-msg ol { list-style: decimal; }
.ds-msg .ds-table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0 8px;
    font-size: 12.5px;
}
.ds-msg .ds-table th,
.ds-msg .ds-table td {
    border: 1px solid rgba(183,154,120,0.2);
    padding: 5px 8px;
    text-align: left;
}
.ds-msg .ds-table th {
    background: rgba(183,154,120,0.12);
    color: #d4c4a8;
    font-weight: 600;
}

/* Bouton reset (header) */
#ds-chat-reset {
    background: transparent;
    border: none;
    color: #737373;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
#ds-chat-reset:hover { color: #d4c4a8; background: rgba(183,154,120,0.1); }

/* Typing indicator */
.ds-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: #0F1A30;
    border: 1px solid rgba(183,154,120,0.15);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: ds-pop 0.22s ease;
}
.ds-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b79a78;
    animation: ds-bounce 1.2s ease infinite;
}
.ds-typing span:nth-child(2) { animation-delay: 0.2s; }
.ds-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ds-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Suggestions */
#ds-chat-suggestions {
    padding: 0 14px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    flex-shrink: 0;
}
.ds-suggestion {
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid rgba(183,154,120,0.3);
    background: transparent;
    color: #b79a78;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    white-space: nowrap;
}
.ds-suggestion:hover {
    background: rgba(183,154,120,0.12);
    color: #d4c4a8;
}
/* Actions rapides (liens de conversion) */
a.ds-suggestion--action {
    text-decoration: none;
    background: rgba(183,154,120,0.10);
    border-color: rgba(183,154,120,0.4);
    color: #d4c4a8;
    font-weight: 500;
}
a.ds-suggestion--action:hover {
    background: linear-gradient(135deg, #b79a78 0%, #8a7358 100%);
    color: #060C16;
    border-color: transparent;
}

/* Curseur clignotant pendant l'effet de frappe */
.ds-msg--typing::after {
    content: '▋';
    display: inline-block;
    margin-left: 1px;
    color: #b79a78;
    animation: ds-caret 0.9s steps(1) infinite;
}
@keyframes ds-caret { 50% { opacity: 0; } }

/* Bulle d'accroche proactive */
#ds-chat-teaser {
    position: fixed;
    bottom: 96px;
    right: 28px;
    z-index: 8998;
    max-width: 250px;
    background: #0F1A30;
    border: 1px solid rgba(183,154,120,0.28);
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 12px 34px rgba(0,0,0,0.55);
    padding: 14px 16px;
    opacity: 0;
    transform: translateY(10px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
#ds-chat-teaser.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
    animation: ds-teaser-in 0.5s ease;
}
@keyframes ds-teaser-in {
    0% { transform: translateY(10px) scale(0.9); }
    60% { transform: translateY(-3px) scale(1.02); }
    100% { transform: translateY(0) scale(1); }
}
#ds-chat-teaser p {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 13.5px;
    line-height: 1.5;
    color: #ece6dc;
    cursor: pointer;
}
#ds-chat-teaser p span {
    font-size: 12px;
    color: #a3a3a3;
}
.ds-teaser__close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: none;
    border: none;
    color: #737373;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
    transition: color 0.15s;
}
.ds-teaser__close:hover { color: #d4c4a8; }

/* Input */
#ds-chat-form {
    padding: 12px 14px;
    border-top: 1px solid rgba(183,154,120,0.14);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #060C16;
}
#ds-chat-input {
    flex: 1;
    resize: none;
    background: #0A1225;
    border: 1px solid rgba(183,154,120,0.2);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: 'Outfit', sans-serif;
    font-size: 13.5px;
    color: #e5e5e5;
    outline: none;
    line-height: 1.4;
    max-height: 96px;
    min-height: 42px;
    transition: border-color 0.18s;
    scrollbar-width: none;
}
#ds-chat-input::-webkit-scrollbar { display: none; }
#ds-chat-input::placeholder { color: #525252; }
#ds-chat-input:focus { border-color: rgba(183,154,120,0.45); }

#ds-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #b79a78 0%, #8a7358 100%);
    color: #060C16;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.18s, transform 0.18s;
}
#ds-chat-send:hover:not(:disabled) { transform: scale(1.06); }
#ds-chat-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* Footer */
#ds-chat-footer {
    padding: 8px 14px;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-size: 10.5px;
    color: #404040;
    border-top: 1px solid rgba(183,154,120,0.08);
    flex-shrink: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    #ds-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 75vh;
        border-radius: 20px 20px 0 0;
    }
    #ds-chat-toggle { bottom: 20px; right: 20px; }
    #ds-chat-teaser { display: none; }
}
