/* OpenAI Chatbox Frontend Styles */

:root {
    --chatbox-primary: 220 90% 56%; /* #1E88E5 */
    --chatbox-primary-dark: 220 90% 45%; /* #1565C0 */
    --chatbox-background: 0 0% 100%; /* #FFFFFF */
    --chatbox-surface: 0 0% 98%; /* #FAFAFA */
    --chatbox-border: 0 0% 90%; /* #E5E5E5 */
    --chatbox-text: 0 0% 20%; /* #333333 */
    --chatbox-text-light: 0 0% 60%; /* #999999 */
    --chatbox-shadow: 0 0% 0%; /* #000000 */
    --chatbox-user-bg: 220 90% 56%; /* #1E88E5 */
    --chatbox-ai-bg: 0 0% 95%; /* #F2F2F2 */
}

/* Dark theme variables */
.theme-dark {
    --chatbox-primary: 220 90% 56%; /* #1E88E5 */
    --chatbox-primary-dark: 220 90% 45%; /* #1565C0 */
    --chatbox-background: 0 0% 15%; /* #262626 */
    --chatbox-surface: 0 0% 18%; /* #2E2E2E */
    --chatbox-border: 0 0% 25%; /* #404040 */
    --chatbox-text: 0 0% 90%; /* #E5E5E5 */
    --chatbox-text-light: 0 0% 70%; /* #B3B3B3 */
    --chatbox-user-bg: 220 90% 56%; /* #1E88E5 */
    --chatbox-ai-bg: 0 0% 22%; /* #383838 */
}

/* Blue theme variables */
.theme-blue {
    --chatbox-primary: 210 100% 50%; /* #0066FF */
    --chatbox-primary-dark: 210 100% 40%; /* #0052CC */
    --chatbox-user-bg: 210 100% 50%; /* #0066FF */
}

/* Green theme variables */
.theme-green {
    --chatbox-primary: 140 84% 47%; /* #16A085 */
    --chatbox-primary-dark: 140 84% 37%; /* #138B75 */
    --chatbox-user-bg: 140 84% 47%; /* #16A085 */
}

/* Main chatbox container */
.openai-chatbox-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Position classes */
.openai-chatbox-container.bottom-right {
    bottom: 20px;
    right: 20px;
}

.openai-chatbox-container.bottom-left {
    bottom: 20px;
    left: 20px;
}

.openai-chatbox-container.top-right {
    top: 20px;
    right: 20px;
}

.openai-chatbox-container.top-left {
    top: 20px;
    left: 20px;
}

/* Chat toggle button */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: hsl(var(--chatbox-primary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px hsla(var(--chatbox-shadow) / 0.15);
    transition: all 0.3s ease;
    position: relative;
    color: white;
}

.chat-toggle:hover {
    background: hsl(var(--chatbox-primary-dark));
    transform: scale(1.05);
}

.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #FF4444;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Chat window */
.chat-window {
    width: 350px;
    height: 500px;
    background: hsl(var(--chatbox-background));
    border-radius: 16px;
    box-shadow: 0 8px 32px hsla(var(--chatbox-shadow) / 0.12);
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 70px;
    right: 0;
    overflow: hidden;
    border: 1px solid hsl(var(--chatbox-border));
}

.bottom-left .chat-window,
.top-left .chat-window {
    left: 0;
    right: auto;
}

.top-right .chat-window,
.top-left .chat-window {
    bottom: auto;
    top: 70px;
}

/* Chat header */
.chat-header {
    background: hsl(var(--chatbox-primary));
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-avatar svg {
    width: 100%;
    height: 100%;
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.chat-close:hover {
    background: hsla(0 0% 100% / 0.1);
}

/* Chat messages */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: hsl(var(--chatbox-surface));
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: hsl(var(--chatbox-border));
    border-radius: 3px;
}

/* Message styling */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-message .message-content {
    background: hsl(var(--chatbox-user-bg));
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: hsl(var(--chatbox-ai-bg));
    color: hsl(var(--chatbox-text));
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: hsl(var(--chatbox-text-light));
    margin-top: 4px;
    padding: 0 4px;
}

/* Chat input */
.chat-input-container {
    border-top: 1px solid hsl(var(--chatbox-border));
    background: hsl(var(--chatbox-background));
}

.chat-input-wrapper {
    display: flex;
    padding: 16px;
    gap: 12px;
    align-items: flex-end;
}

#openai-chat-input {
    flex: 1;
    border: 1px solid hsl(var(--chatbox-border));
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    background: hsl(var(--chatbox-background));
    color: hsl(var(--chatbox-text));
    min-height: 20px;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.2s;
}

#openai-chat-input:focus {
    border-color: hsl(var(--chatbox-primary));
}

#openai-chat-input::placeholder {
    color: hsl(var(--chatbox-text-light));
}

.chat-send-btn {
    background: hsl(var(--chatbox-primary));
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.chat-send-btn:hover:not(:disabled) {
    background: hsl(var(--chatbox-primary-dark));
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading indicator */
.chat-loading {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: hsl(var(--chatbox-text-light));
    font-size: 13px;
}

.loading-dots {
    display: flex;
    gap: 2px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: hsl(var(--chatbox-text-light));
    border-radius: 50%;
    animation: loadingPulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loadingPulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .openai-chatbox-container {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
        top: auto !important;
    }
    
    .chat-window {
        width: calc(100vw - 20px);
        height: 70vh;
        max-height: 500px;
        right: 0;
        left: 0;
        bottom: 70px;
        top: auto;
    }
    
    .chat-toggle {
        width: 50px;
        height: 50px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .message {
        max-width: 90%;
    }
}

/* Hide on very small screens */
@media (max-width: 320px) {
    .openai-chatbox-container {
        display: none;
    }
}

/* Error message styling */
.error-message {
    background: #FFE5E5;
    color: #D32F2F;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin: 8px 0;
    border-left: 4px solid #D32F2F;
}

.theme-dark .error-message {
    background: #4A1A1A;
    color: #FFBABA;
    border-left-color: #FFBABA;
}
