/* AI Chat Widget Styles */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(139, 92, 246, 0.6);
}

.ai-chat-toggle:active {
    transform: scale(1.05);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #1a1a2e;
}

.ai-chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 420px;
    height: 600px;
    background: #1e1e2e;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #2a2a3e;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-chat-widget.collapsed .ai-chat-container {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.ai-chat-header {
    background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    color: white;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-chat-context-bar {
    background: #252535;
    padding: 8px 16px;
    font-size: 12px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #2a2a3e;
    flex-shrink: 0;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #1a1a2e;
}

/* Custom scrollbar */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #3a3a4e;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #4a4a5e;
}

.ai-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: slideIn 0.3s ease;
}

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

.ai-message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-icon {
    font-size: 24px;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-content {
    background: #252535;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    color: #e4e4e7;
    font-size: 14px;
}

.message-content p {
    margin: 0 0 8px 0;
}

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

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

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

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

.user-message .message-content {
    background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);
    color: white;
}

.user-message .message-content strong {
    color: white;
    font-weight: 700;
}

.system-message .message-content {
    background: #2a2a3e;
    border: 1px solid #3a3a4e;
}

.error-message .message-content {
    background: #7f1d1d;
    border: 1px solid #991b1b;
    color: #fecaca;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6b7280;
    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% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-6px);
    }
}

.ai-chat-input-container {
    padding: 16px;
    border-top: 1px solid #2a2a3e;
    display: flex;
    gap: 12px;
    background: #1e1e2e;
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    background: #252535;
    border: 1px solid #3a3a4e;
    border-radius: 8px;
    padding: 12px;
    color: #e4e4e7;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.ai-chat-input:focus {
    outline: none;
    border-color: #8b5cf6;
}

.ai-chat-input::placeholder {
    color: #6b7280;
}

.ai-chat-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.ai-chat-send-btn:active {
    transform: scale(0.95);
}

.ai-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-widget {
        bottom: 10px;
        right: 10px;
    }

    .ai-chat-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: -10px;
        max-width: 100%;
    }

    .ai-chat-toggle {
        width: 56px;
        height: 56px;
    }
}

@media (max-width: 480px) {
    .ai-chat-container {
        width: 100vw;
        height: calc(100vh - 80px);
        bottom: 70px;
        right: -20px;
        border-radius: 16px 16px 0 0;
    }
}

/* Print styles - hide widget when printing */
@media print {
    .ai-chat-widget {
        display: none !important;
    }
}

/* Tab Navigation */
.ai-chat-tabs {
    display: flex;
    background: #252535;
    border-bottom: 1px solid #2a2a3e;
    flex-shrink: 0;
}

.ai-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: #9ca3af;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    position: relative;
}

.ai-tab-btn:hover {
    background: rgba(139, 92, 246, 0.1);
    color: #a78bfa;
}

.ai-tab-btn.active {
    color: #a78bfa;
    border-bottom-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.05);
}

.history-count {
    background: #3a3a4e;
    color: #9ca3af;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.ai-tab-btn.active .history-count {
    background: #8b5cf6;
    color: white;
}

/* Tab Content */
.ai-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-tab-panel {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.ai-tab-panel.active {
    display: flex;
}

/* History Tab Styles */
.history-header {
    padding: 16px;
    border-bottom: 1px solid #2a2a3e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.history-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #e4e4e7;
}

.btn-secondary {
    background: #3a3a4e;
    border: none;
    color: #9ca3af;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #4a4a5e;
    color: #e4e4e7;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.history-list::-webkit-scrollbar-thumb {
    background: #3a3a4e;
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: #4a4a5e;
}

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6b7280;
    text-align: center;
    padding: 40px 20px;
}

.history-empty svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.history-empty p {
    margin: 8px 0 4px 0;
    font-size: 16px;
    font-weight: 500;
}

.history-empty small {
    font-size: 12px;
    opacity: 0.7;
}

.history-item {
    background: #252535;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background: #2a2a3e;
    border-color: #3a3a4e;
    transform: translateX(-2px);
}

.history-item.active {
    background: rgba(139, 92, 246, 0.1);
    border-color: #8b5cf6;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.history-item-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #e4e4e7;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.history-item-delete {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.history-item-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.history-item-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: #6b7280;
}

.history-item-time {
    display: flex;
    align-items: center;
}

.history-item-count {
    display: flex;
    align-items: center;
}

.history-item-count::before {
    content: '•';
    margin-right: 8px;
}

/* Adjustments for Context Bar in Tabs */
.ai-tab-panel[data-panel="chat"] .ai-chat-context-bar {
    background: #252535;
    padding: 8px 16px;
    font-size: 12px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #2a2a3e;
    flex-shrink: 0;
}

/* Ensure chat messages container fills available space in chat tab */
.ai-tab-panel[data-panel="chat"] {
    display: flex;
    flex-direction: column;
}

.ai-tab-panel[data-panel="chat"] .ai-chat-messages {
    flex: 1;
}
