/* ===========================
   CorteX Assistant – Floating Chat
   =========================== */

:root {
    --cortex-primary: #0e5bd8;
    --cortex-primary-dark: #0b47a7;
    --cortex-bg: #ffffff;
    --cortex-bot-bg: #ffffff;
    --cortex-user-bg: #0e5bd8;
    --cortex-radius-lg: 18px;
    --cortex-radius-sm: 10px;
    --cortex-shadow: 0 12px 30px rgba(15, 23, 42, 0.28);
    --cortex-transition: 0.25s ease;
}

/* Floating Chat Icon */
#cortex-chat-circle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: radial-gradient(circle at 20% 0%, #4f9cff, var(--cortex-primary));
    border-radius: 50%;
    color: #ffffff;
    font-size: 26px;
    text-align: center;
    line-height: 56px;
    cursor: pointer;
    box-shadow: var(--cortex-shadow);
    z-index: 9999;
    transition: transform var(--cortex-transition), box-shadow var(--cortex-transition), opacity var(--cortex-transition);
}

#cortex-chat-circle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.35);
}

/* when chat is open (JS adds this) */
#cortex-chat-circle.chat-open {
    opacity: 0.0;
    pointer-events: none;
}

/* Chat Box */
#cortex-chat-box {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 360px;
    height: 470px;
    background: var(--cortex-bg);
    box-shadow: var(--cortex-shadow);
    border-radius: 22px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
/* visible state */
#cortex-chat-box.cortex-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--cortex-primary), #6c2bd9);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    letter-spacing: 0.01em;
    flex-shrink: 0;
}

.chat-header span {
    display: flex;
    flex-direction: column;
    font-size: 14px;
}

.chat-header span::after {
    content: "Online • CorteX Assistant";
    font-size: 11px;
    opacity: 0.85;
}

#chat-close {
    background: rgba(15, 23, 42, 0.2);
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 14px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--cortex-transition), transform var(--cortex-transition);
}

#chat-close:hover {
    background: rgba(15, 23, 42, 0.35);
    transform: rotate(8deg);
}

/* Messages Area */
#chat-messages {
    flex: 1;
    padding: 12px 14px;
    overflow-y: auto;
    background: radial-gradient(circle at top, #f7fbff 0, #eef2ff 28%, #f4f4f5 100%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

/* Nice scrollbar */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}
#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.8);
    border-radius: 999px;
}

/* Message Bubbles */
.bot-msg,
.user-msg {
    max-width: 82%;
    padding: 9px 11px;
    border-radius: var(--cortex-radius-lg);
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-line; /* line breaks from \n */
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

/* Bot bubble */
.bot-msg {
    background: var(--cortex-bot-bg);
    align-self: flex-start;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-bottom-left-radius: 4px;
}

/* User bubble */
.user-msg {
    background: linear-gradient(135deg, var(--cortex-primary), var(--cortex-primary-dark));
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.bot-msg.typing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.typing-label {
    font-size: 12px;
    opacity: 0.8;
}

.typing-dots {
    display: inline-flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: cortex-bounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cortex-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

/* Input Area */
.chat-input-area {
    padding: 9px;
    border-top: 1px solid rgba(148, 163, 184, 0.45);
    display: flex;
    gap: 6px;
    background: #ffffff;
}

#user-input {
    flex: 1;
    padding: 7px 9px;
    border: 1px solid rgba(148, 163, 184, 0.8);
    border-radius: 999px;
    outline: none;
    font-size: 13px;
    transition: border-color var(--cortex-transition), box-shadow var(--cortex-transition);
}

#user-input:focus {
    border-color: var(--cortex-primary);
    box-shadow: 0 0 0 1px rgba(14, 91, 216, 0.2);
}

#send-btn {
    background: linear-gradient(135deg, var(--cortex-primary), #6c2bd9);
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 70px;
    transition: transform var(--cortex-transition), box-shadow var(--cortex-transition), opacity var(--cortex-transition);
}

#send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(14, 91, 216, 0.35);
}

#send-btn:disabled {
    opacity: 0.55;
    cursor: default;
    box-shadow: none;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #cortex-chat-box {
        width: calc(100% - 24px);
        right: 12px;
        bottom: 80px;
        height: 420px;
        border-radius: 20px;
    }

    #cortex-chat-circle {
        bottom: 16px;
        right: 16px;
    }
}
