/* =============================================
   Bizouk Chat Widget - Remplacement Chatbase
   ============================================= */

/* Variables — Bizouk gold theme */
:root {
    --bzk-chat-primary: #b8860b;
    --bzk-chat-primary-dark: #9a7209;
    --bzk-chat-primary-light: #d4a930;
    --bzk-chat-bg: #ffffff;
    --bzk-chat-bg-secondary: #faf9f5;
    --bzk-chat-text: #1a1a1a;
    --bzk-chat-text-muted: #888;
    --bzk-chat-border: #e8e4d9;
    --bzk-chat-user-bg: #b8860b;
    --bzk-chat-user-text: #ffffff;
    --bzk-chat-bot-bg: #faf9f5;
    --bzk-chat-bot-text: #333;
    --bzk-chat-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    --bzk-chat-radius: 16px;
    --bzk-chat-width: 400px;
    --bzk-chat-height: 600px;
}

/* Container principal */
#bzk-chat-widget {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#bzk-chat-widget *,
#bzk-chat-widget *::before,
#bzk-chat-widget *::after {
    box-sizing: border-box;
}

/* Bandeau en bas à gauche */
.bzk-chat-toggle {
    position: fixed;
    left: 16px;
    bottom: 0;
    width: auto;
    height: auto;
    border-radius: 10px 10px 0 0;
    background: var(--bzk-chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    box-shadow: 0 -2px 10px rgba(184, 134, 11, 0.18);
    transition: all 0.25s ease;
    writing-mode: horizontal-tb;
    text-orientation: initial;
}

.bzk-chat-toggle:hover {
    background: var(--bzk-chat-primary-dark);
    box-shadow: 0 -3px 14px rgba(184, 134, 11, 0.28);
}

.bzk-chat-toggle.active {
    opacity: 0.85;
}

.bzk-chat-toggle svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    transition: transform 0.3s ease;
}

.bzk-chat-toggle::after {
    content: 'Assistant Bizouk';
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    writing-mode: horizontal-tb;
}

.bzk-chat-toggle.active svg.icon-chat {
    display: none;
}

.bzk-chat-toggle.active svg.icon-close {
    display: block;
}

.bzk-chat-toggle svg.icon-close {
    display: none;
}

/* Badge notification */
.bzk-chat-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 600;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Fenêtre de chat */
.bzk-chat-window {
    position: fixed;
    bottom: 42px;
    left: 16px;
    width: var(--bzk-chat-width);
    height: var(--bzk-chat-height);
    max-height: calc(100vh - 60px);
    background: var(--bzk-chat-bg);
    border-radius: var(--bzk-chat-radius);
    box-shadow: var(--bzk-chat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: bzk-chat-slide-in 0.3s ease;
}

@keyframes bzk-chat-slide-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.bzk-chat-window.open {
    display: flex;
}

@keyframes bzk-chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.bzk-chat-header {
    background: var(--bzk-chat-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.bzk-chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bzk-chat-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

.bzk-chat-header-info {
    flex: 1;
    min-width: 0;
}

.bzk-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}

.bzk-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
    margin: 0;
}

.bzk-chat-header-actions {
    display: flex;
    gap: 8px;
}

.bzk-chat-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.bzk-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.bzk-chat-header-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

/* Zone des messages */
.bzk-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bzk-chat-bg-secondary);
}

.bzk-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.bzk-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.bzk-chat-messages::-webkit-scrollbar-thumb {
    background: var(--bzk-chat-border);
    border-radius: 2px;
}

/* Message bulle */
.bzk-chat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: bzk-msg-appear 0.2s ease;
}

@keyframes bzk-msg-appear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bzk-chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bzk-chat-msg.assistant {
    align-self: flex-start;
}

.bzk-chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.bzk-chat-msg.assistant .bzk-chat-msg-avatar {
    background: var(--bzk-chat-primary);
    color: #fff;
}

.bzk-chat-msg.user .bzk-chat-msg-avatar {
    background: var(--bzk-chat-border);
    color: var(--bzk-chat-text-muted);
}

.bzk-chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.bzk-chat-msg.assistant .bzk-chat-msg-bubble {
    background: var(--bzk-chat-bot-bg);
    color: var(--bzk-chat-bot-text);
    border-bottom-left-radius: 4px;
}

.bzk-chat-msg.user .bzk-chat-msg-bubble {
    background: var(--bzk-chat-user-bg);
    color: var(--bzk-chat-user-text);
    border-bottom-right-radius: 4px;
}

.bzk-chat-msg-time {
    font-size: 11px;
    color: var(--bzk-chat-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.bzk-chat-msg.user .bzk-chat-msg-time {
    text-align: right;
}

/* Indicateur de frappe */
.bzk-chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--bzk-chat-bot-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
}

.bzk-chat-typing.visible {
    display: flex;
}

.bzk-chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bzk-chat-text-muted);
    animation: bzk-typing-bounce 1.4s ease-in-out infinite;
}

.bzk-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.bzk-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bzk-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Zone de saisie */
.bzk-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--bzk-chat-border);
    background: var(--bzk-chat-bg);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.bzk-chat-input {
    flex: 1;
    border: 1px solid var(--bzk-chat-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.2s;
    background: var(--bzk-chat-bg);
    color: var(--bzk-chat-text);
}

.bzk-chat-input:focus {
    border-color: var(--bzk-chat-primary);
}

.bzk-chat-input::placeholder {
    color: var(--bzk-chat-text-muted);
}

.bzk-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bzk-chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.bzk-chat-send-btn:hover {
    background: var(--bzk-chat-primary-dark);
}

.bzk-chat-send-btn:disabled {
    background: var(--bzk-chat-border);
    cursor: not-allowed;
}

.bzk-chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Formulaire d'escalade */
.bzk-chat-escalation {
    display: none;
    padding: 16px;
    background: #fefce8;
    border-top: 1px solid #fde68a;
    flex-shrink: 0;
}

.bzk-chat-escalation.visible {
    display: block;
}

.bzk-chat-escalation h4 {
    font-size: 13px;
    font-weight: 600;
    color: #92400e;
    margin: 0 0 10px;
}

.bzk-chat-escalation-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bzk-chat-escalation input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #fde68a;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fff;
}

.bzk-chat-escalation input:focus {
    border-color: var(--bzk-chat-primary);
}

.bzk-chat-escalation-btns {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.bzk-chat-escalation-submit {
    flex: 1;
    padding: 8px 16px;
    background: var(--bzk-chat-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.bzk-chat-escalation-submit:hover {
    background: var(--bzk-chat-primary-dark);
}

.bzk-chat-escalation-cancel {
    padding: 8px 16px;
    background: transparent;
    color: var(--bzk-chat-text-muted);
    border: 1px solid var(--bzk-chat-border);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.bzk-chat-escalation-cancel:hover {
    background: var(--bzk-chat-bg-secondary);
}

/* Panneau historique */
.bzk-chat-history-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bzk-chat-bg);
    z-index: 10;
    display: none;
    flex-direction: column;
}

.bzk-chat-history-panel.open {
    display: flex;
}

.bzk-chat-history-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--bzk-chat-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.bzk-chat-history-back {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bzk-chat-bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bzk-chat-history-back svg {
    width: 16px;
    height: 16px;
    fill: var(--bzk-chat-text);
}

.bzk-chat-history-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--bzk-chat-text);
}

.bzk-chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.bzk-chat-history-item {
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.bzk-chat-history-item:hover {
    background: var(--bzk-chat-bg-secondary);
}

.bzk-chat-history-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--bzk-chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bzk-chat-history-item-date {
    font-size: 11px;
    color: var(--bzk-chat-text-muted);
    margin-top: 2px;
}

.bzk-chat-history-item-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #fee2e2;
    color: #dc2626;
    margin-left: 6px;
}

/* Footer satisfaction */
.bzk-chat-satisfaction {
    display: none;
    padding: 12px 16px;
    border-top: 1px solid var(--bzk-chat-border);
    text-align: center;
    background: var(--bzk-chat-bg);
    flex-shrink: 0;
}

.bzk-chat-satisfaction.visible {
    display: block;
}

.bzk-chat-satisfaction p {
    font-size: 12px;
    color: var(--bzk-chat-text-muted);
    margin: 0 0 8px;
}

.bzk-chat-satisfaction-stars {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.bzk-chat-satisfaction-star {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    opacity: 0.3;
    transition: opacity 0.2s, transform 0.2s;
}

.bzk-chat-satisfaction-star:hover,
.bzk-chat-satisfaction-star.active {
    opacity: 1;
    transform: scale(1.2);
}

/* Powered by */
.bzk-chat-powered {
    padding: 6px;
    text-align: center;
    font-size: 10px;
    color: var(--bzk-chat-text-muted);
    background: var(--bzk-chat-bg);
    flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 480px) {
    #bzk-chat-widget {
        bottom: 0;
        left: 0;
    }

    .bzk-chat-toggle {
        left: 8px;
        padding: 8px 14px;
    }

    .bzk-chat-toggle::after {
        font-size: 11px;
    }

    .bzk-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 42px;
        left: 8px;
    }
}
