/* AI Agent Chat Widget Styles */

#ai-agent-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Widget positioning */
.ai-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

.ai-widget-top-right {
    top: 20px;
    right: 20px;
}

.ai-widget-top-left {
    top: 20px;
    left: 20px;
}

/* Toggle button */
#ai-agent-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

#ai-agent-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Chat window */
#ai-agent-chat {
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e1e5e9;
}

/* Chat header */
.ai-chat-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: inherit;
}

#ai-chat-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

#ai-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Messages area */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message styles */
.ai-message,
.user-message {
    display: flex;
}

.ai-message {
    justify-content: flex-start;
}

.user-message {
    justify-content: flex-end;
}

.ai-message-content,
.user-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.ai-message-content {
    background-color: #f1f3f4;
    color: #333;
}

.user-message-content {
    color: white;
}

/* Enhanced Message Status and Metadata Styles */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
    padding: 0 4px;
}

.user-message .message-meta {
    justify-content: flex-end;
}

.ai-message .message-meta {
    justify-content: flex-start;
}

.message-time {
    font-size: 11px;
    color: #999;
    opacity: 0.7;
}

.message-status {
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s ease;
}

.message-status.sending {
    color: #ffa500;
    animation: pulse 1.5s infinite;
}

.message-status.sent {
    color: #4caf50;
}

.message-status.error {
    color: #f44336;
    cursor: pointer;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Message status indicators */
.status-sending {
    opacity: 0.7;
}

.status-sent {
    opacity: 1;
}

.status-error {
    border-left: 3px solid #f44336;
}

/* Connection Status Indicator */
.connection-status {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    border-radius: 4px;
    margin: 8px 16px;
    transition: all 0.3s ease;
}

.connection-status.status-connected {
    background-color: #e8f5e8;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.connection-status.status-processing {
    background-color: #fff3e0;
    color: #ef6c00;
    border: 1px solid #ffcc02;
}

.connection-status.status-error {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef5350;
}

.connection-status.status-reconnecting {
    background-color: #ffeaa7;
    color: #d63031;
    border: 1px solid #fdcb6e;
    animation: pulse 1.5s infinite;
}

/* Header Controls */
.header-controls {
    display: flex;
    gap: 8px;
    margin-left: auto;
    margin-right: 8px;
}

.header-btn {
    background: none;
    border: none;
    color: inherit;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    opacity: 0.85;
}

.header-btn:hover {
    opacity: 1;
}

.header-btn:active {
    opacity: 0.7;
}

/* Retry Button */
.retry-btn {
    background: #f44336;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    margin-left: 8px;
    transition: all 0.2s ease;
}

.retry-btn:hover {
    background: #d32f2f;
    transform: scale(1.05);
}

/* System Messages */
.system-message {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1976d2;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    margin: 8px 16px;
    border: 1px solid #2196f3;
    position: relative;
    animation: slideIn 0.3s ease;
}

.system-icon {
    margin-right: 6px;
    font-size: 14px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}




/* Input area */
.ai-chat-input {
    padding: 16px 20px;
    border-top: 1px solid #e1e5e9;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

#ai-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s ease;
    min-width: 0;
    /* Allows flex item to shrink below its content size */
    width: 100%;
    /* Ensures full width within flex container */
}

#ai-chat-input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

#ai-chat-input::placeholder {
    color: #9ca3af;
}

#ai-chat-send {
    background-color: #0073aa;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    /* Prevents button from shrinking */
}

#ai-chat-send:hover {
    background-color: #005a87;
    transform: scale(1.05);
}

#ai-chat-send:active {
    transform: scale(0.95);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    #ai-agent-chat {
        width: calc(100vw - 20px);
        height: calc(100vh - 40px);
        margin: 10px;
    }

    .header-controls {
        flex-direction: column;
        gap: 4px;
    }

    .header-btn {
        font-size: 10px;
        padding: 3px 6px;
    }

    .ai-chat-input {
        padding: 12px 16px;
        gap: 8px;
    }

    #ai-chat-input {
        padding: 10px 14px;
        font-size: 16px;
        /* Prevents zoom on iOS */
        border-radius: 16px;
    }

    #ai-chat-send {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }
}

/* Enhanced focus states for accessibility */
.retry-btn:focus,
.header-btn:focus {
    outline: 2px solid #2196f3;
    outline-offset: 2px;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Enhanced hover effects */
.user-message-content:hover,
.ai-message-content:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

/* Notification badges */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f44336;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Enhanced Typing Indicator Animation */
.typing-indicator {
    opacity: 0.9;
    animation: fadeIn 0.3s ease-in;
}

.typing-animation {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots .dot {
    width: 8px;
    height: 8px;
    background-color: #666;
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

.typing-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.typing-text {
    font-size: 14px;
    color: #666;
    font-style: italic;
}

@keyframes typingDots {
    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typewriter Effect */
.typewriter-active::after {
    content: '|';
    color: #0073aa;
    animation: typewriterCursor 1s infinite;
    font-weight: bold;
}

@keyframes typewriterCursor {
    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* Enhanced AI Message Formatting */
.ai-message-content {
    line-height: 1.6;
}

.ai-message-content p {
    margin: 0 0 12px 0;
}

.ai-message-content p:last-child {
    margin-bottom: 0;
}

.ai-message-content ul,
.ai-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-message-content li {
    margin: 4px 0;
}

.ai-message-content strong {
    font-weight: 600;
    color: #333;
}

.ai-message-content em {
    font-style: italic;
    color: #555;
}

.ai-message-content code {
    background-color: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    padding: 2px 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    color: #d14;
}

.ai-message-content pre {
    background-color: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
}

.ai-message-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: #333;
    font-size: 13px;
    line-height: 1.4;
}

/* Improved Message Spacing */
.ai-message,
.user-message {
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}