/**
 * TEX8 AI Assistant Widget Styles
 * Based on web-solutions design but adapted for WordPress
 */

/* Floating Button */
#tex8-ai-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #FF6B35 0%, #FF8C42 100%);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: none;
}

#tex8-ai-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.6);
}

#tex8-ai-button svg {
    width: 28px;
    height: 28px;
    color: white;
}

#tex8-ai-button.hidden {
    display: none;
}

/* Bottom Left Position */
body.tex8-ai-position-bottom-left #tex8-ai-button {
    left: 24px;
    right: auto;
}

/* Backdrop */
#tex8-ai-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#tex8-ai-backdrop.hidden {
    display: none;
}

#tex8-ai-backdrop:not(.hidden) {
    opacity: 1;
}

/* Widget Container */
#tex8-ai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 40px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

#tex8-ai-widget.hidden {
    display: none;
}

#tex8-ai-widget.active {
    opacity: 1;
    transform: translateY(0);
}

/* Widget Header */
.tex8-ai-header {
    background: linear-gradient(135deg, #FF6B35 0%, #FF8C42 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tex8-ai-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tex8-ai-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.tex8-ai-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.tex8-ai-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.tex8-ai-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.tex8-ai-close svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Messages Container */
#tex8-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
}

/* Message Bubbles */
.user-message,
.ai-message {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 14px;
    animation: messageSlideIn 0.3s ease;
}

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

.user-message {
    background: linear-gradient(135deg, #FF6B35 0%, #FF8C42 100%);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.ai-message {
    background: white;
    color: #1f2937;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #f3f4f6;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Input Container */
.tex8-ai-input {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: white;
    border-radius: 0 0 16px 16px;
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
}

.tex8-ai-input-wrapper {
    flex: 1;
    display: flex;
    align-items: stretch;
}

.tex8-ai-actions {
    display: flex;
    flex-direction: row;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* Attach button styling via icon-btn class */
.tex8-ai-attach-icon {
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
}

#tex8-ai-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e5e7eb !important;
    border-radius: 10px !important;
    font-size: 14px !important;
    outline: none !important;
    transition: all 0.2s ease;
    resize: none !important;
    min-height: 60px;
    max-height: 100px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    line-height: 1.4 !important;
    background: #f8f9fa !important;
    color: #1f2937 !important;
    box-shadow: none !important;
}

#tex8-ai-input:focus {
    border-color: #FF6B35 !important;
    background: white !important;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1) !important;
    outline: none !important;
}

#tex8-ai-input::placeholder {
    color: #9ca3af !important;
    opacity: 1 !important;
}

#tex8-ai-send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: linear-gradient(135deg, #FF6B35 0%, #FF8C42 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    flex-shrink: 0;
}

#tex8-ai-send svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

#tex8-ai-send:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.5);
}

#tex8-ai-send:active:not(:disabled) {
    transform: translateY(0);
}

#tex8-ai-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Icon buttons (mic and attach) */
.tex8-ai-icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6B7280;
    font-size: 20px;
    padding: 6px;
    flex-shrink: 0;
}

.tex8-ai-icon-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.tex8-ai-icon-btn:hover {
    background: #E5E7EB;
    border-color: #D1D5DB;
}

.tex8-ai-icon-btn:active {
    transform: scale(0.95);
}

/* Links in messages */
.ai-message a {
    color: #FF6B35;
    text-decoration: underline;
}

.ai-message a:hover {
    color: #FF8C42;
}

/* Prevent body scroll when widget is open */
body.tex8-ai-no-scroll {
    overflow: hidden;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #tex8-ai-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .tex8-ai-header {
        border-radius: 0;
    }

    .tex8-ai-input {
        border-radius: 0;
    }

    #tex8-ai-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
}

/* Scrollbar Styling */
#tex8-ai-messages::-webkit-scrollbar {
    width: 6px;
}

#tex8-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

#tex8-ai-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

#tex8-ai-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Attachments Preview Container */
#tex8-ai-attachments {
    padding: 8px 12px;
    background: #f8f9fa;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    max-height: 120px;
    overflow-y: auto;
}

#tex8-ai-attachments.hidden {
    display: none;
}

.attachment-preview {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    border: 2px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.attachment-preview img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-preview .file-icon {
    font-size: 28px;
    margin-bottom: 4px;
}

.attachment-preview span {
    font-size: 10px;
    color: #6b7280;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.remove-attachment {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: background 0.2s;
    font-weight: bold;
}

.remove-attachment:hover {
    background: rgba(220, 38, 38, 1);
}

/* Attachment count badge */
.attachment-count {
    display: inline-block;
    margin-left: 6px;
    opacity: 0.7;
    font-size: 14px;
}

/* Mic button disabled */
#tex8-ai-mic-btn {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Recording indicator */
#tex8-ai-mic-btn.recording {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    color: white !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Typing dots animation */
.typing-dots {
    display: flex;
    gap: 6px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* User message content wrapper */
.user-message-content {
    display: inline;
}

/* AI message content wrapper */
.ai-message-content {
    display: inline;
}

/* Sources display (for RAG results) */
.ai-message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #6b7280;
}

.ai-message-sources h4 {
    margin: 0 0 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.ai-message-sources ul {
    margin: 0;
    padding-left: 20px;
}

.ai-message-sources li {
    margin-bottom: 4px;
}

/* Actions display (for action buttons) */
.ai-message-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-message-action-btn {
    padding: 8px 16px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-message-action-btn:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

/* Mobile adjustments for attachments */
@media (max-width: 768px) {
    #tex8-ai-attachments {
        max-height: 100px;
    }

    .attachment-preview {
        width: 70px;
        height: 70px;
    }
}
