/* ========================================
   VEXPO CMS - AI Chat Frontend
   vex_front_chat.css
   Skeleton CSS Variables
   ======================================== */

/* ========== VARIABLES ========== */
:root {
    --vex-chat-primary: var(--primary);
    --vex-chat-primary-dark: var(--primary-dark);
    --vex-chat-bg: var(--white);
    --vex-chat-text: var(--text-primary);
    --vex-chat-text-light: var(--text-muted);
    --vex-chat-border: var(--gray-200);
    --vex-chat-user-bg: var(--primary);
    --vex-chat-user-text: var(--white);
    --vex-chat-assistant-bg: var(--gray-50);
    --vex-chat-assistant-text: var(--text-primary);
    --vex-chat-shadow: var(--shadow-2xl);
    --vex-chat-radius: 16px;
}

/* ========== CHAT BUTTON ========== */
.vex-chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--vex-chat-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-glow-primary);
    transition: all 0.3s ease;
    z-index: 9998;
    color: var(--white);
    border: none;
    font-size: 24px;
}

.vex-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(139, 92, 246, 0.6);
}

.vex-chat-button.active {
    transform: rotate(90deg);
}

.vex-chat-button .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: var(--white);
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* ========== CHAT WINDOW ========== */
.vex-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 550px;
    max-height: calc(100vh - 140px);
    background: var(--vex-chat-bg);
    border-radius: var(--vex-chat-radius);
    box-shadow: var(--vex-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    animation: chatSlideIn 0.3s ease;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========== HEADER ========== */
.vex-chat-header {
    background: linear-gradient(135deg, var(--vex-chat-primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.vex-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vex-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.vex-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vex-chat-avatar .fallback-icon {
    color: var(--white);
    font-size: 20px;
}

.vex-chat-header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.vex-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}

.status-dot.online {
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.vex-chat-header-actions {
    display: flex;
    gap: 4px;
}

.vex-chat-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 16px;
}

.vex-chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ========== HISTORY PANEL ========== */
.vex-chat-history-panel {
    position: absolute;
    top: 72px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--vex-chat-bg);
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.history-header {
    padding: 16px;
    border-bottom: 1px solid var(--vex-chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history-header h5 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--vex-chat-text);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.history-item:hover {
    background: var(--vex-chat-assistant-bg);
}

.history-item.active {
    background: rgba(139, 92, 246, 0.1);
    border-left: 3px solid var(--vex-chat-primary);
    padding-left: 13px;
}

.history-item-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--vex-chat-text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 12px;
    color: var(--vex-chat-text-light);
}

.history-empty,
.history-loading {
    padding: 40px 20px;
    text-align: center;
    color: var(--vex-chat-text-light);
    font-size: 14px;
}

/* ========== MESSAGES ========== */
.vex-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--vex-chat-bg);
}

.vex-chat-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

.vex-chat-message.user {
    align-self: flex-end;
}

.vex-chat-message.assistant {
    align-self: flex-start;
}

.vex-chat-message .message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.vex-chat-message.user .message-content {
    background: var(--vex-chat-user-bg);
    color: var(--vex-chat-user-text);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

.vex-chat-message.assistant .message-content {
    background: var(--vex-chat-assistant-bg);
    color: var(--vex-chat-assistant-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--vex-chat-border);
}

.vex-chat-message .message-content code {
    background: rgba(139, 92, 246, 0.1);
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.vex-chat-message .message-content a {
    color: var(--primary);
    text-decoration: underline;
    transition: color 0.2s;
}

.vex-chat-message .message-content a:hover {
    color: var(--primary-dark);
}

.vex-chat-message .message-time {
    font-size: 11px;
    color: var(--vex-chat-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.vex-chat-message.user .message-time {
    text-align: right;
}

/* ========== TYPING INDICATOR ========== */
.vex-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--vex-chat-text-light);
    font-size: 13px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--vex-chat-text-light);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ========== INPUT ========== */
.vex-chat-input-container {
    padding: 12px 16px;
    border-top: 1px solid var(--vex-chat-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--vex-chat-bg);
}

.vex-chat-input {
    flex: 1;
    border: 1px solid var(--vex-chat-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white);
    color: var(--text-primary);
}

.vex-chat-input::placeholder {
    color: var(--vex-chat-text-light);
}

.vex-chat-input:focus {
    outline: none;
    border-color: var(--vex-chat-primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.vex-chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--vex-chat-primary);
    color: var(--white);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 18px;
}

.vex-chat-send-btn:hover:not(:disabled) {
    background: var(--vex-chat-primary-dark);
    transform: scale(1.05);
    box-shadow: var(--shadow-glow-primary);
}

.vex-chat-send-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    opacity: 0.6;
}

/* ========== FOOTER ========== */
.vex-chat-footer {
    padding: 8px 16px;
    text-align: center;
    font-size: 11px;
    color: var(--vex-chat-text-light);
    border-top: 1px solid var(--vex-chat-border);
    background: var(--gray-50);
}

/* ========== TOAST ========== */
.vex-chat-toast {
    position: fixed;
    bottom: 180px;
    right: 24px;
    background: var(--text-dark);
    color: var(--white);
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 10000;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    max-width: 300px;
    box-shadow: var(--shadow-lg);
}

.vex-chat-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.vex-chat-toast.success {
    background: var(--success);
}

.vex-chat-toast.error {
    background: var(--danger);
}

.vex-chat-toast.warning {
    background: var(--warning);
}

/* ========== SCROLLBAR ========== */
.vex-chat-messages::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 6px;
}

.vex-chat-messages::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.vex-chat-messages::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

.vex-chat-messages::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .vex-chat-window {
        width: 360px;
        height: 480px;
        bottom: 80px;
    }

    .vex-chat-message {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .vex-chat-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .vex-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        max-height: 70vh;
        border-radius: 0;
    }
    
    .vex-chat-toast {
        left: 16px;
        right: 16px;
        bottom: 100px;
    }

    .vex-chat-message {
        max-width: 95%;
    }

    .vex-chat-header {
        padding: 12px 16px;
    }

    .vex-chat-messages {
        padding: 12px;
    }

    .vex-chat-input-container {
        padding: 10px 12px;
    }
}

/* ========== DARK MODE (optional) ========== */
@media (prefers-color-scheme: dark) {
    .vex-chat-window.dark-mode {
        --vex-chat-bg: var(--gray-900);
        --vex-chat-text: var(--gray-100);
        --vex-chat-text-light: var(--gray-400);
        --vex-chat-border: var(--gray-800);
        --vex-chat-assistant-bg: var(--gray-800);
        --vex-chat-assistant-text: var(--gray-100);
    }

    .vex-chat-window.dark-mode .vex-chat-input {
        background: var(--gray-800);
        color: var(--gray-100);
        border-color: var(--gray-700);
    }

    .vex-chat-window.dark-mode .vex-chat-input::placeholder {
        color: var(--gray-500);
    }
}