/* CNAPE ChatBot - Chat Specific Styles */

/* Chat Container */
.chat-container {
    position: relative;
    width: 100%;
}

/* Enhanced Chat Messages */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* Message Animations */
.message {
    opacity: 0;
    animation: messageSlideIn 0.3s ease forwards;
}

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

/* Message Content Enhancements */
.message-content p {
    margin: 0 0 var(--spacing-2) 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content ul {
    margin: var(--spacing-2) 0;
    padding-left: var(--spacing-4);
}

.message-content li {
    margin-bottom: var(--spacing-1);
}

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
}

/* Sources Display */
.message-sources {
    margin-top: var(--spacing-3);
    padding-top: var(--spacing-3);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: var(--font-size-sm);
    opacity: 0.8;
}

.source-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    margin-bottom: var(--spacing-1);
    cursor: pointer;
    padding: var(--spacing-1);
    border-radius: var(--border-radius-sm);
    transition: background-color 0.2s ease;
}

.source-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.source-icon {
    width: 16px;
    height: 16px;
    color: var(--primary-blue);
}

.source-text {
    flex: 1;
}

/* Enhanced Quick Suggestions */
.quick-suggestions {
    background: var(--gray-50);
}

.suggestion-chip {
    border: 1px solid var(--gray-200);
    white-space: nowrap;
}

.suggestion-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Chat Input Enhancements */
.chat-input-wrapper {
    position: relative;
}

.chat-input {
    resize: none;
    min-height: 44px;
    transition: all 0.2s ease;
}

.chat-input:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.send-button {
    min-width: 44px;
    height: 44px;
}

.send-button i {
    width: 20px;
    height: 20px;
}

/* Character Counter */
.char-counter {
    position: absolute;
    bottom: -24px;
    right: 0;
    font-size: var(--font-size-xs);
    color: var(--gray-400);
}

.char-counter.warning {
    color: var(--primary-orange);
}

.char-counter.danger {
    color: var(--primary-red);
}

/* Chat Status Indicators */
.chat-status-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-2) var(--spacing-4);
    background: var(--gray-100);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-green);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7);
    }
    
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(5, 150, 105, 0);
    }
    
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0);
    }
}

/* Error States */
.message-error {
    background: #fee2e2 !important;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.chat-error {
    padding: var(--spacing-3);
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: var(--border-radius-sm);
    color: #991b1b;
    font-size: var(--font-size-sm);
    margin: var(--spacing-2) 0;
}

.retry-button {
    background: var(--primary-red);
    color: white;
    border: none;
    padding: var(--spacing-1) var(--spacing-3);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    cursor: pointer;
    margin-left: var(--spacing-2);
    transition: background-color 0.2s ease;
}

.retry-button:hover {
    background: #dc2626;
}

/* Chat Minimized State */
.chat-widget.minimized {
    height: 60px;
    overflow: hidden;
}

.chat-widget.minimized .chat-messages,
.chat-widget.minimized .quick-suggestions,
.chat-widget.minimized .chat-input-container {
    display: none;
}

/* Category Highlights in Chat */
.category-mention {
    background: linear-gradient(120deg, transparent 0%, transparent 40%, var(--primary-blue) 40%, var(--primary-blue) 60%, transparent 60%);
    background-size: 200% 100%;
    background-position: 100% 0;
    transition: background-position 0.3s ease;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 500;
}

.category-mention:hover {
    background-position: 0 0;
    color: white;
    cursor: pointer;
}

/* Chat Floating Action Button */
.chat-fab {
    position: fixed;
    bottom: var(--spacing-6);
    right: var(--spacing-6);
    width: 60px;
    height: 60px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
}

.chat-fab:hover {
    transform: scale(1.1);
    background: #1d4ed8;
}

.chat-fab.show {
    display: flex;
}

/* Message Reactions */
.message-reactions {
    margin-top: var(--spacing-2);
    display: flex;
    gap: var(--spacing-1);
}

.reaction-btn {
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: 20px;
    padding: var(--spacing-1) var(--spacing-2);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: var(--spacing-1);
}

.reaction-btn:hover {
    background: var(--gray-100);
}

.reaction-btn.active {
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
}

/* Auto-resize textarea */
.chat-input {
    resize: none;
    overflow: hidden;
    min-height: 44px;
    max-height: 120px;
}

/* Connection Status */
.connection-status {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    color: white;
    padding: var(--spacing-2) var(--spacing-4);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.connection-status.show {
    opacity: 1;
}

.connection-status.error {
    background: var(--primary-red);
}

.connection-status.success {
    background: var(--primary-green);
}

/* Mobile Chat Optimizations */
@media (max-width: 768px) {
    .chat-widget {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        border-radius: var(--border-radius) var(--border-radius) 0 0;
        max-height: 80vh;
        z-index: 1000;
    }
    
    .chat-messages {
        height: 50vh;
    }
    
    .quick-suggestions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .suggestion-chip {
        text-align: center;
        white-space: normal;
    }
    
    .chat-input-wrapper {
        flex-direction: column;
        gap: var(--spacing-2);
    }
    
    .send-button {
        align-self: flex-end;
        width: 100px;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .category-card {
        padding: var(--spacing-4);
    }
    
    .chat-fab {
        bottom: var(--spacing-4);
        right: var(--spacing-4);
        width: 56px;
        height: 56px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .message-content {
        border: 2px solid;
    }
    
    .bot-message .message-content {
        border-color: var(--gray-400);
    }
    
    .user-message .message-content {
        border-color: var(--primary-blue);
    }
    
    .suggestion-chip {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .message,
    .suggestion-chip,
    .category-card,
    .send-button,
    .chat-fab {
        animation: none;
        transition: none;
    }
    
    .typing-dots span {
        animation: none;
    }
    
    .status-dot {
        animation: none;
    }
}

/* Focus indicators for accessibility */
.chat-input:focus,
.send-button:focus,
.suggestion-chip:focus,
.category-card:focus,
.modal-close:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Voice Button Styles */
.voice-button {
    background: #64748b;
    color: white;
    border: none;
    padding: var(--spacing-3);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    margin-right: var(--spacing-2);
    position: relative;
}

/* TTS Controls Styles */
.tts-controls {
    position: relative;
    margin-right: var(--spacing-2);
}

.tts-button {
    background: #059669; /* Green for TTS */
    color: white;
    border: none;
    padding: var(--spacing-3);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    position: relative;
}

.tts-settings {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: var(--spacing-4);
    min-width: 250px;
    z-index: 1000;
    margin-bottom: var(--spacing-2);
}

.tts-settings-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

.tts-setting {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-1);
}

.tts-setting label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.tts-setting select {
    padding: var(--spacing-2);
    border: 1px solid #d1d5db;
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    background: white;
    color: #374151;
}

.tts-setting select:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
    border-color: var(--primary-blue);
}

.tts-button:hover {
    background: #047857;
    transform: translateY(-1px);
}

.tts-button.disabled {
    background: #dc2626; /* Red when disabled */
    cursor: pointer; /* Still clickable to re-enable */
    transform: none;
}

.tts-button.disabled:hover {
    background: #b91c1c; /* Darker red on hover when disabled */
}

.tts-button.speaking {
    background: #dc2626;
    animation: pulse-speaking 1.5s infinite;
}

.tts-button i {
    width: 20px;
    height: 20px;
}

.voice-button:hover {
    background: #475569;
    transform: translateY(-1px);
}

.voice-button.listening {
    background: #ef4444;
    animation: pulse-red 1.5s infinite;
}

.voice-button.processing {
    background: #f59e0b;
    animation: spin 1s linear infinite;
}

.voice-button:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    transform: none;
}

.voice-button i {
    width: 20px;
    height: 20px;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
    }
}

@keyframes pulse-speaking {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
    }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.voice-hint {
    color: var(--primary-blue);
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.voice-hint.hidden {
    display: none;
}

/* Enhanced Voice Button Styles for Mobile */
.voice-button.mobile-mode {
    background: #8b5cf6; /* Purple for server-side mode */
}

.voice-button.mobile-mode:hover {
    background: #7c3aed;
}

.voice-button.mobile-mode.listening {
    background: #ef4444;
    animation: pulse-red 1.5s infinite;
}

.voice-button.mobile-mode.processing {
    background: #f59e0b;
    animation: spin 1s linear infinite;
}

/* Mobile-specific voice hints */
@media (max-width: 768px) {
    .voice-hint {
        font-size: 0.875rem;
    }
    
    .voice-button {
        min-width: 48px; /* Larger touch target */
        height: 48px;
    }
}

/* Connection status indicator for speech */
.voice-button.offline {
    background: var(--gray-400);
    cursor: not-allowed;
}

.voice-button.offline:hover {
    background: var(--gray-400);
    transform: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
