/* Aclas AI Assistant Public Styles - Enhanced with Hold-to-Record */

/* Chat Widget Container */
.aclas-ai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Chat Trigger Button */
.aclas-ai-trigger {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.aclas-ai-trigger:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
}

.aclas-ai-trigger.active {
    transform: scale(0.95);
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.trigger-icon {
    color: white;
    transition: transform 0.3s ease;
}

.aclas-ai-trigger:hover .trigger-icon {
    transform: scale(1.1);
}

.trigger-pulse {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    70% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* Chat Interface */
.aclas-ai-chat-interface {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.aclas-ai-chat-interface.show {
    display: flex;
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Chat Header */
.aclas-ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-mini {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.avatar-status {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    position: absolute;
    bottom: 2px;
    right: 2px;
    border: 2px solid white;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.status-text {
    font-size: 12px;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Mode Toggle */
.aclas-ai-mode-toggle {
    display: flex;
    background: #f8fafc;
    margin: 0;
    border-bottom: 1px solid #e2e8f0;
}

.mode-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: white;
    color: #667eea;
    border-bottom: 2px solid #667eea;
}

.mode-btn:hover:not(.active) {
    background: #f1f5f9;
    color: #475569;
}

/* Chat Content */
.aclas-ai-chat-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.chat-mode {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
}

.chat-mode.active {
    display: flex;
}

/* Text Chat Mode */
.aclas-ai-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.aclas-ai-messages::-webkit-scrollbar {
    width: 6px;
}

.aclas-ai-messages::-webkit-scrollbar-track {
    background: #f8fafc;
}

.aclas-ai-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease-out;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    flex-shrink: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.bot-avatar {
    width: 32px;
    height: 32px;
    background: #f1f5f9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 44px);
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Enhanced Message Content Formatting - Single Container */
.response-container {
    padding: 14px 18px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
}

.bot-message .response-container {
    background: #374151;
    color: white !important;
    border-bottom-right-radius: 6px;
}

.user-message .response-container {
    background: #374151;
    color: white !important;
    border-bottom-right-radius: 6px;
}

/* Paragraphs within response container */
.response-container p {
    margin: 0 0 12px 0;
    padding: 0;
    background: none !important;
    border-radius: 0 !important;
    line-height: 1.5;
    color: inherit !important;
    font-size: 14px;
}

.response-container p:last-child {
    margin-bottom: 0;
}

/* Ensure text visibility */
.bot-message .response-container,
.bot-message .response-container p,
.bot-message .response-container strong,
.bot-message .response-container em {
    color: white;
}

.user-message .response-container,
.user-message .response-container p,
.user-message .response-container strong,
.user-message .response-container em {
    color: white !important;
}

/* Legacy support for old p-based messages */
.message-content p:not(.response-container p) {
    margin: 0;
    padding: 14px 18px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.bot-message .message-content p:not(.response-container p) {
    background: #f1f5f9;
    color: #374151;
    border-bottom-left-radius: 6px;
}

.user-message .message-content p:not(.response-container p) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

/* Formatted Content Styles within response container */
.response-container strong {
    font-weight: 600;
    color: inherit;
}

.response-container em {
    font-style: italic;
    color: inherit;
}

/* Enhanced embedded links - descriptive text style */
.embedded-link {
    color: #3b82f6;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    font-weight: 500;
    transition: all 0.2s ease;
    word-break: break-word;
    display: inline;
    padding: 0;
    background: none;
    border-radius: 0;
}

.embedded-link:hover {
    color: #1d4ed8;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.user-message .embedded-link {
    color: #bfdbfe;
    text-decoration-color: #bfdbfe;
}

.user-message .embedded-link:hover {
    color: #dbeafe;
    text-decoration-color: #dbeafe;
}

/* Legacy link styles for fallback */
.message-content a:not(.embedded-link) {
    color: #3b82f6;
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s ease;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.1);
}

.user-message .message-content a:not(.embedded-link) {
    color: #bfdbfe;
    background: rgba(255, 255, 255, 0.2);
}

/* Message time */
.message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
    padding: 0 16px;
}

/* Error messages */
.error-message p {
    border-left: 3px solid #ef4444 !important;
    background: #fef2f2 !important;
    color: #dc2626 !important;
}

/* Input Area */
.aclas-ai-input-area {
    padding: 20px;
    border-top: 1px solid #e2e8f0;
    background: white;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#aclas-ai-message-input {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
    max-height: 120px;
    min-height: 40px;
}

#aclas-ai-message-input:focus {
    border-color: #667eea;
}

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.send-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Voice Chat Mode */
.voice-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.avatar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

#avatar-viewer {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.avatar-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.placeholder-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.7;
}

.avatar-placeholder p {
    color: #6b7280;
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

.avatar-status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: statusPulse 2s infinite;
}

/* Enhanced Voice Controls */
.voice-controls {
    margin-top: 20px;
    text-align: center;
}

.voice-btn {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 auto 16px;
    position: relative;
    overflow: hidden;
    font-family: inherit;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.3);
}

.voice-btn:hover:not(:disabled) {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(239, 68, 68, 0.4);
}

.voice-btn:active {
    transform: scale(0.98);
}

/* Enhanced Recording State */
.voice-btn.recording {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    animation: recordingPulse 1s infinite ease-in-out;
    transform: scale(1.02);
    box-shadow: 0 8px 30px rgba(16, 185, 129, 0.4);
}

@keyframes recordingPulse {
    0%, 100% { 
        transform: scale(1.02);
        box-shadow: 0 8px 30px rgba(16, 185, 129, 0.4);
    }
    50% { 
        transform: scale(1.08);
        box-shadow: 0 12px 40px rgba(16, 185, 129, 0.6);
    }
}

.voice-btn:disabled {
    background: #9ca3af !important;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: none !important;
    animation: none !important;
}

.btn-text {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
    text-align: center;
}

/* Recording Indicator */
.recording-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #ffffff;
    border-radius: 50%;
    margin-right: 6px;
    animation: recordingBlink 1s infinite;
}

@keyframes recordingBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Voice Feedback */
.voice-feedback {
    margin-top: 16px;
}

.voice-visualizer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 40px;
    margin-bottom: 12px;
}

.voice-bar {
    width: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    transition: all 0.2s ease;
}

.voice-bar:nth-child(1) { height: 20px; }
.voice-bar:nth-child(2) { height: 30px; }
.voice-bar:nth-child(3) { height: 40px; }
.voice-bar:nth-child(4) { height: 25px; }
.voice-bar:nth-child(5) { height: 15px; }

.voice-visualizer.active .voice-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    animation: voiceWave 0.8s infinite alternate;
}

@keyframes voiceWave {
    0% { transform: scaleY(0.5); }
    100% { transform: scaleY(1.5); }
}

.voice-bar:nth-child(1) { animation-delay: 0.1s; }
.voice-bar:nth-child(2) { animation-delay: 0.2s; }
.voice-bar:nth-child(3) { animation-delay: 0.3s; }
.voice-bar:nth-child(4) { animation-delay: 0.4s; }
.voice-bar:nth-child(5) { animation-delay: 0.5s; }

.feedback-text {
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    margin: 0;
    line-height: 1.4;
    transition: color 0.2s ease;
}

/* Conversation History */
.conversation-history {
    max-height: 150px;
    overflow-y: auto;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.conversation-item {
    margin-bottom: 16px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 12px;
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.speaker {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 12px;
}

.speaker.bot {
    background: #e0e7ff;
    color: #3730a3;
}

.speaker.user {
    background: #fef3c7;
    color: #92400e;
}

.timestamp {
    font-size: 11px;
    color: #9ca3af;
}

.conversation-text {
    font-size: 13px;
    line-height: 1.4;
    color: #374151;
    margin: 0;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* Source Indicator */
.source-indicator {
    padding: 8px 16px;
    margin: 8px 20px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 16px;
    font-size: 12px;
    color: #667eea;
    text-align: center;
    animation: fadeInUp 0.3s ease-out;
}

/* Session Persistence Indicator */
.session-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 500;
    animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Enhanced Notification Styles */
.aclas-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000000;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInRight 0.3s ease-out;
    backdrop-filter: blur(10px);
}

.aclas-notification.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

.aclas-notification-success {
    border-left: 4px solid #10b981;
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
}

.aclas-notification-error {
    border-left: 4px solid #ef4444;
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}

.aclas-notification-info {
    border-left: 4px solid #3b82f6;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

.notification-message {
    flex: 1;
    font-size: 14px;
    color: #374151;
    line-height: 1.4;
}

.notification-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #9ca3af;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.notification-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #374151;
}

/* Enhanced Animation Keyframes */
@keyframes slideInRight {
    from { 
        transform: translateX(100%); 
        opacity: 0; 
    }
    to { 
        transform: translateX(0); 
        opacity: 1; 
    }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Touch-friendly improvements for mobile */
@media (max-width: 480px) {
    .aclas-ai-chat-interface {
        width: calc(100vw - 40px);
        height: calc(100vh - 140px);
        max-height: 600px;
    }
    
    .aclas-ai-widget {
        right: 10px;
        bottom: 10px;
    }
    
    .aclas-ai-trigger {
        width: 50px;
        height: 50px;
    }
    
    .aclas-ai-chat-interface {
        bottom: 70px;
    }

    .message-content {
        max-width: calc(100% - 32px);
    }

    .message-content p {
        padding: 10px 12px;
        font-size: 13px;
    }

    .voice-btn {
        width: 80px;
        height: 80px;
        margin-bottom: 12px;
    }

    .btn-text {
        font-size: 10px;
    }

    .aclas-notification {
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .avatar-container {
        min-height: 250px;
    }

    #avatar-viewer {
        width: 150px;
        height: 150px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .aclas-ai-trigger {
        border: 2px solid #000;
    }
    
    .voice-btn {
        border: 2px solid #000;
    }
    
    .message-content p {
        border: 1px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .pulse,
    .trigger-pulse,
    .recording-indicator,
    .voice-visualizer.active .voice-bar {
        animation: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .aclas-ai-chat-interface {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .aclas-ai-input-area {
        background: #1f2937;
        border-top-color: #374151;
    }
    
    #aclas-ai-message-input {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
    
    .bot-message .response-container {
        background: #374151;
        color: #f9fafb;
    }
    
    .conversation-item {
        background: #374151;
    }
    
    .conversation-text {
        color: #e5e7eb;
    }

    .feedback-text {
        color: #9ca3af;
    }

    .aclas-notification {
        background: #374151;
        border-color: #4b5563;
    }

    .notification-message {
        color: #f9fafb;
    }
}

/* Print styles */
@media print {
    .aclas-ai-widget {
        display: none !important;
    }
}