/* ============================================================
   KING CHARLY — Assistant IA Chat Widget
   Premium Apple-like design
   ============================================================ */

/* ---- Floating Button ---- */
.ai-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary, #007AFF);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(0, 122, 255, 0.35);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.ai-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 32px rgba(0, 122, 255, 0.45);
}
.ai-chat-toggle:active { transform: scale(0.96); }
.ai-chat-toggle[aria-expanded="true"] .ai-chat-icon-open { display: none; }
.ai-chat-toggle[aria-expanded="true"] .ai-chat-icon-close { display: block !important; }
.ai-chat-toggle[aria-expanded="false"] .ai-chat-icon-close { display: none; }
.ai-chat-toggle[aria-expanded="false"] .ai-chat-icon-open { display: block; }

/* ---- Panel ---- */
.ai-chat-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 9998;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--color-surface, #fff);
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.ai-chat-panel[aria-hidden="false"] {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--color-primary, #007AFF);
    color: #fff;
    flex-shrink: 0;
}
.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-chat-title {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}
.ai-chat-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}
.ai-chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34C759;
    display: inline-block;
}
.ai-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.ai-chat-close:hover { background: rgba(255, 255, 255, 0.35); }

/* ---- Messages ---- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.12); border-radius: 4px; }

/* ---- Message ---- */
.ai-chat-message {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: aiMsgIn 0.25s ease-out;
}
@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ai-chat-message--bot {
    align-self: flex-start;
}
.ai-chat-message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.ai-chat-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary, #007AFF);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}
.ai-chat-message--user .ai-chat-message-avatar {
    background: var(--color-secondary, #5856D6);
}
.ai-chat-message-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}
.ai-chat-message--bot .ai-chat-message-content {
    background: var(--color-bg, #F2F2F7);
    color: var(--color-text, #1C1C1E);
    border-bottom-left-radius: 6px;
}
.ai-chat-message--user .ai-chat-message-content {
    background: var(--color-primary, #007AFF);
    color: #fff;
    border-bottom-right-radius: 6px;
}
.ai-chat-message-content p { margin: 0 0 6px; }
.ai-chat-message-content p:last-child { margin-bottom: 0; }
.ai-chat-message-content a {
    color: var(--color-primary, #007AFF);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ai-chat-message--user .ai-chat-message-content a {
    color: #fff;
}

/* ---- Welcome message ---- */
.ai-chat-message--welcome .ai-chat-message-content {
    padding: 14px 16px;
}

/* ---- Suggestions ---- */
.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.ai-chat-suggestion {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--color-primary, #007AFF);
    background: transparent;
    color: var(--color-primary, #007AFF);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}
.ai-chat-suggestion:hover {
    background: var(--color-primary, #007AFF);
    color: #fff;
}

/* ---- Typing indicator ---- */
.ai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-items: center;
}
.ai-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-secondary, #8E8E93);
    animation: aiTypingBounce 1.2s infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---- Error message ---- */
.ai-chat-message--error .ai-chat-message-content {
    background: var(--color-danger, #FF3B30);
    color: #fff;
    border-bottom-left-radius: 6px;
}

/* ---- Input Area ---- */
.ai-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: var(--color-surface, #fff);
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: var(--color-bg, #F2F2F7);
    color: var(--color-text, #1C1C1E);
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    border-color: var(--color-primary, #007AFF);
}
.ai-chat-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary, #007AFF);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.ai-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: scale(0.9);
}
.ai-chat-send:not(:disabled):hover {
    transform: scale(1.05);
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
    .ai-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
    .ai-chat-toggle[aria-expanded="true"] {
        opacity: 0;
        pointer-events: none;
    }
    .ai-chat-panel {
        bottom: 84px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
        height: min(60vh, 560px);
        max-height: calc(100dvh - 120px);
        border-radius: 20px;
    }
    .ai-chat-suggestions {
        gap: 4px;
    }
    .ai-chat-suggestion {
        font-size: 11px;
        padding: 5px 10px;
    }
}

/* ---- Dark mode (auto) ---- */
@media (prefers-color-scheme: dark) {
    .ai-chat-panel {
        background: #1C1C1E;
        box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
    }
    .ai-chat-message--bot .ai-chat-message-content {
        background: #2C2C2E;
        color: #F2F2F7;
    }
    .ai-chat-input {
        background: #2C2C2E;
        color: #F2F2F7;
        border-color: rgba(255, 255, 255, 0.1);
    }
    .ai-chat-input-area {
        border-top-color: rgba(255, 255, 255, 0.08);
        background: #1C1C1E;
    }
    .ai-chat-suggestion {
        border-color: rgba(255, 255, 255, 0.2);
        color: rgba(255, 255, 255, 0.8);
    }
}
