/* chat_widget.css */
/* Chat Widget Styles */

/* Variables */
:root {
    --primary-color: #4F46E5;
    --primary-light: #818CF8;
    --secondary-color: #E5E7EB;
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --bg-color: #FFFFFF;
    --message-user-bg: #4F46E5;
    --message-assistant-bg: #F3F4F6;
    --message-admin-bg: #10B981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --link-color: #3B82F6;
    --link-color-hover: #1D4ED8;
    --link-color-light: #60A5FA;
    --link-color-light-hover: #93C5FD;
}

/* Chat Widget Container */
#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    /* Default size for mobile */
    width: 350px; 
    height: 520px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    background-color: var(--bg-color);
    border: none;
    box-shadow: var(--shadow-lg);
    border-radius: 16px;
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    
    /* Remove smooth transition */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}

/* Larger default size for non-mobile screens */
@media screen and (min-width: 481px) {
    #ai-chat-widget {
        width: 400px; /* Increased width */
        height: 600px; /* Increased height */
    }
}

/* Show the chat widget with animation */
#ai-chat-widget.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Override transform when both active and keyboard-visible */
/* TODO: Remove this workaround when Chrome/iOS fixes keyboard viewport bug */
#ai-chat-widget.active.keyboard-visible {
    transform: translateY(-15%) scale(1);
}

/* Chat Toggle Button */
#ai-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#ai-chat-toggle:hover {
    transform: scale(1.1);
}

#ai-chat-toggle img {
    width: 100%;
    height: auto;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

/* Chat Header */
#ai-chat-header {
    background-color: var(--primary-color);
    color: white;
    padding: 16px 20px;
    font-size: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#ai-chat-header #ai-chat-name {
    font-weight: 600;
    flex-grow: 1;
    letter-spacing: 0.01em;
}

#ai-chat-close-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#ai-chat-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Chat Messages */
#ai-chat-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* For Firefox */
#ai-chat-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.ai-chat-message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
}

.ai-chat-message:hover {
    transform: translateY(-1px);
}

.ai-chat-message.user {
    background-color: var(--message-user-bg);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.ai-chat-message.assistant {
    background-color: var(--message-assistant-bg);
    color: var(--text-primary);
    margin-right: auto;
    border-bottom-left-radius: 4px;
    line-height: 1.6;
    padding: 14px 18px;
}

.ai-chat-message.admin {
    background-color: #10B981; /* Emerald color for admin */
    color: white;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    border-radius: 16px;
}

/* Message link styles */
.ai-chat-message a {
    color: var(--link-color);
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s ease;
}

.ai-chat-message a:hover {
    color: var(--link-color-hover);
    text-decoration: underline;
}

/* Style links in user messages differently */
.ai-chat-message.user a {
    color: var(--link-color-light);
}

.ai-chat-message.user a:hover {
    color: var(--link-color-light-hover);
}

/* Chat Input Area */
#ai-chat-input-area {
    padding: 12px;
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--secondary-color);
    width: 100%;
    box-sizing: border-box;
    position: relative;
    bottom: 0;
}

#ai-chat-emoji-btn {
    background-color: transparent;
    border: none;
    cursor: pointer;
    font-size: 20px;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

#ai-chat-emoji-btn:hover {
    background-color: var(--secondary-color);
}

#emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 16px;
    background-color: var(--bg-color);
    border: 1px solid var(--secondary-color);
    border-radius: 12px;
    padding: 8px;
    width: 280px;
    display: flex;
    flex-wrap: wrap;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

#emoji-picker-content {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    width: 100%;
}

#emoji-picker span {
    cursor: pointer;
    padding: 6px;
    font-size: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

#emoji-picker span:hover {
    background-color: var(--secondary-color);
}

#ai-chat-input {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
    padding: 10px 14px;
    border: 2px solid var(--secondary-color);
    border-radius: 12px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background-color: var(--bg-color);
}

#ai-chat-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#ai-chat-attach-btn {
    background-color: transparent;
    border: none;
    cursor: pointer;
    font-size: 20px;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

#ai-chat-attach-btn:hover {
    background-color: var(--secondary-color);
}

#ai-chat-send-btn {
    background-color: var(--primary-color);
    border: none;
    color: white;
    padding: 10px 16px;
    cursor: pointer;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

#ai-chat-send-btn:hover {
    background-color: var(--primary-light);
    transform: translateY(-1px);
}

/* User Info Form */
#ai-chat-user-info {
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 12px;
}

#ai-chat-user-info input {
    padding: 12px 16px;
    border: 2px solid var(--secondary-color);
    border-radius: 12px;
    font-size: 15px;
    transition: all 0.2s ease;
}

#ai-chat-user-info input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    outline: none;
}

#ai-chat-start-btn {
    background-color: var(--primary-color);
    border: none;
    color: white;
    padding: 14px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s ease;
}

#ai-chat-start-btn:hover {
    background-color: var(--primary-light);
    transform: translateY(-1px);
}

/* Suggestions */
.ai-chat-suggestion {
    background-color: var(--message-assistant-bg);
    padding: 16px;
    border-radius: 12px;
    margin: 16px 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    box-shadow: var(--shadow-sm);
}

/* Countdown Timer */
#countdown-timer {
    display: inline-block;
    padding: 4px 8px;
    background-color: var(--secondary-color);
    border-radius: 6px;
    margin-top: 8px;
    font-family: monospace;
    font-size: 14px;
    color: var(--text-primary);
}

/* Cancel Human Support Button */
#cancel-human-support {
    background-color: #DC2626;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    margin-top: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

#cancel-human-support:hover {
    background-color: #EF4444;
    transform: translateY(-1px);
}

/* Mobile Responsive Adjustments */
@media screen and (max-width: 480px) {
    #ai-chat-widget {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    #ai-chat-toggle {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
    }

    #ai-chat-header {
        padding: 12px 16px;
    }

    #ai-chat-messages {
        padding: 16px;
    }

    #ai-chat-input-area {
        padding: 10px;
    }

    #ai-chat-input {
        padding: 8px 12px;
    }

    #ai-chat-send-btn {
        padding: 8px 14px;
    }

    #emoji-picker {
        width: calc(100% - 32px);
        left: 16px;
        right: 16px;
    }

    .ai-chat-message {
        max-width: 90%;
    }
}

/* Small height screens */
@media screen and (max-height: 600px) {
    #ai-chat-widget {
        height: calc(100vh - 40px);
    }
}

/* Resize Handle */
#ai-chat-resize-handle {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    border-left: 4px solid rgba(0, 0, 0, 0.4);
    border-top: 4px solid rgba(0, 0, 0, 0.4);
    z-index: 10000;
}

/* iOS Keyboard Workaround - Shift widget up by 15% when keyboard is visible */
/* TODO: Remove this workaround when Chrome/iOS fixes keyboard viewport bug */
#ai-chat-widget.keyboard-visible {
    transform: translateY(-15%);
    transition: transform 0.3s ease;
}

#ai-chat-widget:not(.keyboard-visible) {
    transform: translateY(0);
    transition: transform 0.3s ease;
}

/* Lock body scroll when widget is open on mobile */
@media screen and (max-width: 480px) {
    body.chat-widget-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100%;
        height: 100%;
    }
}
