/* AI Chat Assistant Styles - Updated 2025-08-14 */

/* Chat History Formatting */
.json-block {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
}

.inline-code {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 2px 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 11px;
    color: var(--text-primary);
}

.chat-preview-message .message-content {
    line-height: 1.6;
    word-wrap: break-word;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    flex-wrap: wrap;
}

.chat-controls .model-selector {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    min-width: 120px;
}

/* Context Memory Toggle */
.context-memory-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.context-memory-control:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-color);
}

.context-memory-control input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.context-memory-control label {
    cursor: pointer;
    user-select: none;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.context-memory-control label i {
    font-size: 14px;
}

.chat-controls .secondary-btn {
    padding: 6px 12px;
    font-size: 12px;
    height: auto;
    min-height: 32px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Prompt Detection UI */
.prompt-detection {
    background: rgba(34, 139, 34, 0.1);
    border: 1px solid rgba(34, 139, 34, 0.3);
    border-radius: 8px;
    padding: 16px;
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: fadeIn 0.3s ease-out;
}

.prompt-detection i {
    color: #22c55e;
    font-size: 18px;
}

.prompt-detection span {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 12px;
    flex: 1;
}

.import-prompts-btn {
    background: rgb(145, 231, 0);
    color: #333;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 180px;
}

.import-prompts-btn:hover:not(:disabled) {
    background: #16a34a;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.import-prompts-btn:disabled {
    background: #6b7280;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.copy-json-btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 100px;
}

.copy-json-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

/* AI Chat Module Layout */
#ai-chat-assistant-module {
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#ai-chat-assistant-module .module-header {
    margin-bottom: 0;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 500px;
    max-height: calc(100vh - 225px);
    background: var(--bg-dark);
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    font-family: Menlo, monospace;
    margin: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    scroll-behavior: smooth;
    background: var(--bg-panel);
}

.chat-message {
    display: flex;
    margin-bottom: 12px;
    animation: messageSlideIn 0.3s ease-out;
    max-width: 100%;
}

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

.user-message {
    justify-content: flex-end;
}

.assistant-message {
    justify-content: flex-start;
    color: rgb(145, 231, 0);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin: 0 12px;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--accent-color);
    color: white;
    order: 2;
}

.assistant-message .message-avatar {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.message-content {
    max-width: 70%;
    position: relative;
}

.user-message .message-content {
    order: 1;
}

.message-text {
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 16px;
    color: var(--text-primary);
    line-height: 1.5;
    word-wrap: break-word;
}

.user-message .message-text {
    background: var(--accent-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-message .message-text {
    border-bottom-left-radius: 4px;
}

.message-text ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
}

/* Thinking Message Styles */
.thinking-message {
    justify-content: flex-start;
}

.thinking-message .message-avatar {
    background: rgba(145, 231, 0, 0.2);
    color: #91e700;
    border: 1px solid rgba(145, 231, 0, 0.3);
}

.thinking-message .message-text {
    background: rgba(145, 231, 0, 0.1);
    border: 1px solid rgba(145, 231, 0, 0.3);
    color: #91e700;
    font-style: italic;
    position: relative;
    animation: thinkingPulse 2s ease-in-out infinite;
}

.thinking-message .message-text::after {
    content: '...';
    animation: typingDots 1.5s ease-in-out infinite;
    margin-left: 2px;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

@keyframes typingDots {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    } 40% {
        transform: scale(1);
    }
}

/* Typing Dots Animation */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

.welcome-message .message-text {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.chat-input-container {
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    background: var(--bg-secondary);
    margin-bottom: 90px;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 8px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-color);
}

.file-upload-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
    flex-shrink: 0;
}

.file-upload-btn:hover {
    background: var(--accent-color-hover);
    transform: translateY(-1px);
}

.file-preview {
    margin: 8px 0;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.file-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 4px;
    margin-bottom: 8px;
}

.file-preview .file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 12px;
}

.file-preview .remove-file {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    margin-left: auto;
}

#chat-input {
    flex: 1;
    background: #272727;
    border: none;
    color: var(--text-primary);
    font-size: 12px;
    line-height: 1.4;
    resize: none;
    min-height: 20px;
    max-height: 120px;
    padding: 8px 12px;
    border-radius: 8px;
}

#chat-input:focus {
    outline: none;
}

#chat-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    background: var(--accent-color);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.send-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

.chat-status {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 20px;
    padding: 4px 8px;
}

.chat-status .token-warning {
    color: #ff9800 !important;
    font-weight: 600;
    animation: pulse 2s ease-in-out infinite;
}

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

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-color);
}

.typing-indicator .session-cost {
    margin-left: auto;
    font-size: 11px;
    color: #91e700;
    font-weight: 600;
}

/* Token Cost Indicator */
.token-cost-indicator {
    animation: slideIn 0.3s ease-out;
    margin-top: 10px;
}

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

.token-cost-indicator.fade-out {
    animation: fadeOut 0.5s ease-out;
    opacity: 0;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.cost-breakdown {
    background: linear-gradient(135deg, rgba(145, 231, 0, 0.1) 0%, rgba(145, 231, 0, 0.05) 100%);
    border: 1px solid rgba(145, 231, 0, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 12px;
}

.cost-title {
    font-weight: 600;
    color: #91e700;
    margin-bottom: 8px;
    font-size: 13px;
}

.cost-line {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    color: var(--text-secondary);
}

.cost-line span:first-child {
    color: var(--text-muted);
}

.cost-line span:last-child {
    font-family: 'Monaco', 'Menlo', monospace;
    color: var(--text-primary);
}

.cost-line.total {
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    padding-top: 8px;
    font-weight: 600;
}

.cost-line.total span {
    color: #91e700;
}

.cost-line.session-total {
    background: rgba(145, 231, 0, 0.08);
    margin: 8px -8px -4px -8px;
    padding: 8px 8px;
    border-radius: 4px;
    font-weight: 700;
}

.cost-line.session-total span {
    color: #91e700;
}

/* Scrollbar styling for chat messages */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

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

/* Chat History Modal */
#chat-history-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

#chat-history-modal .modal-content {
    max-width: 1200px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
}

.chat-history-modal {
    background: var(--bg-dark) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    color: var(--text-primary) !important;
}

.chat-history-modal .modal-header {
    background: var(--bg-panel) !important;
    border-bottom: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 15px 20px !important;
    border-radius: 12px 12px 0 0 !important;
}

.chat-history-modal .modal-header h3 {
    color: var(--text-primary) !important;
    margin: 0 !important;
}

.chat-history-modal .modal-body {
    background: var(--bg-dark) !important;
    padding: 0 !important;
    display: flex !important;
    height: 600px !important;
    max-height: calc(100vh - 200px) !important;
}

.chat-history-layout {
    display: flex;
    width: 100%;
    height: 100%;
}

.chat-sessions-sidebar {
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    width: 280px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.chat-sessions-panel {
    background: var(--bg-panel) !important;
    border-right: 1px solid var(--border-color) !important;
    width: 300px !important;
    display: flex !important;
    flex-direction: column !important;
}

.chat-sessions-header {
    background: var(--bg-card) !important;
    padding: 15px !important;
    border-bottom: 1px solid var(--border-color) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
}

.chat-sessions-header h4 {
    color: var(--text-primary) !important;
    margin: 0 !important;
}

.chat-sessions-list {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 10px !important;
}

.chat-preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

.chat-preview-panel {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    background: var(--bg-dark) !important;
}

.chat-preview-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 15px 20px !important;
    border-bottom: 1px solid var(--border-color) !important;
    background: var(--bg-panel) !important;
}

.chat-preview-header h4 {
    color: var(--text-primary) !important;
    margin: 0 !important;
}

.chat-preview-actions {
    display: flex !important;
    gap: 10px !important;
}

.chat-preview-content {
    flex: 1 !important;
    background: var(--bg-dark) !important;
    margin: 0 !important;
    padding: 20px !important;
    overflow-y: auto !important;
    color: var(--text-primary) !important;
}

.chat-preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 16px;
    opacity: 0.5;
}

.chat-preview-empty i {
    font-size: 64px;
}

.chat-preview-empty div {
    font-size: 14px;
}

/* Preview Message Styling - Clean & Readable */
.preview-msg {
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.preview-msg.user {
    border-left: 4px solid var(--accent-color);
}

.preview-msg.assistant {
    border-left: 4px solid rgb(145, 231, 0);
}

.preview-msg-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
}

.preview-role {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.preview-msg-num {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.preview-msg-content {
    padding: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 13px;
    max-height: 200px;
    overflow: hidden;
    word-wrap: break-word;
}

.message-role {
    font-weight: 700 !important;
    padding: 12px 16px 8px 16px !important;
    font-size: 13px !important;
    text-transform: uppercase !important;
    letter-spacing: 1px !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.user-message .message-role {
    color: rgba(255, 255, 255, 0.95) !important;
    background: rgba(255, 255, 255, 0.1) !important;
}

.assistant-message .message-role {
    color: var(--accent-blue) !important;
    background: rgba(59, 130, 246, 0.1) !important;
}

.assistant-message .message-content {
    color: var(--text-primary) !important;
}

.json-content {
    background: var(--bg-dark) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    padding: 16px !important;
    margin: 12px 0 !important;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
    font-size: 13px !important;
    overflow-x: auto !important;
    position: relative !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.json-content pre {
    margin: 0 !important;
    color: var(--text-primary) !important;
    line-height: 1.5 !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
}

.json-import-btn {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    background: var(--accent-blue) !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.json-import-btn:hover {
    background: #0ea5e9 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
}

.chat-preview-empty {
    text-align: center !important;
    color: var(--text-secondary) !important;
    padding: 50px !important;
}

.chat-preview-empty i {
    font-size: 48px !important;
    margin-bottom: 15px !important;
    opacity: 0.3 !important;
    color: var(--text-secondary) !important;
}

.chat-session-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-session-item:hover {
    background: var(--bg-panel);
    border-color: var(--accent-color);
}

.chat-session-item.selected {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.chat-session-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-session-item.selected .chat-session-title {
    color: white;
}

.chat-session-preview {
    display: none; /* Hide preview text for cleaner look */
}

.chat-session-date {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 400;
}

.chat-session-item.selected .chat-session-date {
    color: rgba(255, 255, 255, 0.8);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 150px);
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chat-messages {
        padding: 12px;
    }
    
    .chat-input-container {
        padding: 12px;
    }
}
