/**
 * ============================================
 * AI CHAT PANEL STYLES
 * File: css/components/ai-chat.css
 * ============================================
 * Styles for the AI Chat Panel in Stock Analysis page
 */

/* ==========================================
   CHAT PANEL CONTAINER
   ========================================== */

.ai-chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    overflow: hidden;
    height: 600px;
    max-height: 70vh;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
}

/* Dark theme specific */
[data-theme="dark"] .ai-chat-panel {
    background: #1a1b2e;
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.ai-chat-panel.minimized {
    height: auto;
    max-height: none;
}

.ai-chat-panel.minimized .ai-chat-body,
.ai-chat-panel.minimized .ai-chat-input-area {
    display: none;
}

/* ==========================================
   CHAT HEADER
   ========================================== */

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-bottom: none;
}

[data-theme="dark"] .ai-chat-header {
    background: linear-gradient(135deg, #4338ca, #6366f1);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.ai-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-icon {
    font-size: 24px;
}

.ai-chat-title {
    font-weight: 600;
    font-size: 15px;
}

.ai-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    opacity: 0.9;
}

.ai-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: pulse 2s infinite;
}

.ai-chat-status-dot.connected {
    background: #22c55e;
    animation: none;
}

.ai-chat-status-dot.disconnected {
    background: #ef4444;
}

.ai-chat-status-dot.reconnecting {
    background: #f59e0b;
    animation: pulse 0.8s infinite;
}

.ai-chat-status-dot.failed {
    background: #ef4444;
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-model-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.ai-chat-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-chat-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================
   MODEL SELECTOR
   ========================================== */

.ai-model-selector {
    position: relative;
}

.ai-model-selector select {
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 28px 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-model-selector select:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ai-model-selector select:focus {
    outline: none;
    border-color: white;
}

.ai-model-selector select option {
    background: var(--bg-color);
    color: var(--text-color);
}

.ai-model-selector::after {
    content: '▾';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 10px;
}

/* ==========================================
   CHAT BODY (MESSAGES)
   ========================================== */

.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-secondary, #f8fafc);
}

[data-theme="dark"] .ai-chat-body {
    background: linear-gradient(180deg, #12132a 0%, #0d0e1a 100%);
}

/* Custom Scrollbar */
.ai-chat-body::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ai-chat-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==========================================
   CHAT MESSAGES
   ========================================== */

.ai-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.ai-chat-message.assistant {
    align-self: flex-start;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* Dark theme: AI message stands out */
[data-theme="dark"] .ai-chat-message.assistant {
    background: linear-gradient(135deg, #1e2140 0%, #252850 100%);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #e2e8f0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-chat-message.user {
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4);
}

.ai-chat-message.system {
    align-self: center;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 16px;
    border-radius: 20px;
}

.ai-chat-message.error {
    align-self: center;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ==========================================
   RECONNECT BANNER
   ========================================== */

.ai-chat-reconnect-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #f59e0b;
    animation: fadeInUp 0.3s ease;
}

[data-theme="dark"] .ai-chat-reconnect-banner {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.4);
    color: #fbbf24;
}

.ai-chat-reconnect-banner .reconnect-icon {
    font-size: 16px;
}

.ai-chat-reconnect-banner .reconnect-message {
    flex: 1;
}

.ai-chat-reconnect-banner .reconnect-retry-btn {
    padding: 6px 12px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-chat-reconnect-banner .reconnect-retry-btn:hover {
    background: #d97706;
    transform: scale(1.02);
}

[data-theme="dark"] .ai-chat-reconnect-banner .reconnect-retry-btn {
    background: #d97706;
}

[data-theme="dark"] .ai-chat-reconnect-banner .reconnect-retry-btn:hover {
    background: #b45309;
}

/* Message Meta */
.ai-message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 11px;
    opacity: 0.7;
}

.ai-message-model {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 4px;
    color: var(--primary-color);
}

/* Streaming Indicator */
.ai-streaming-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    color: var(--text-muted);
    font-size: 14px;
}

.ai-streaming-dots {
    display: flex;
    gap: 4px;
}

.ai-streaming-dots span {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: streamingBounce 1.4s infinite ease-in-out;
}

.ai-streaming-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-streaming-dots span:nth-child(2) { animation-delay: -0.16s; }
.ai-streaming-dots span:nth-child(3) { animation-delay: 0; }

@keyframes streamingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* ==========================================
   EMPTY STATE
   ========================================== */

.ai-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    padding: 32px;
}

[data-theme="dark"] .ai-chat-empty {
    color: #94a3b8;
}

[data-theme="dark"] .ai-chat-empty-title {
    color: #e2e8f0;
}

.ai-chat-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.ai-chat-empty-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.ai-chat-empty-text {
    font-size: 13px;
    line-height: 1.6;
    max-width: 280px;
}

.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
    justify-content: center;
}

.ai-chat-suggestion {
    padding: 8px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-color);
}

[data-theme="dark"] .ai-chat-suggestion {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    color: #c7d2fe;
}

.ai-chat-suggestion:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

[data-theme="dark"] .ai-chat-suggestion:hover {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* ==========================================
   INPUT AREA
   ========================================== */

.ai-chat-input-area {
    padding: 12px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
}

[data-theme="dark"] .ai-chat-input-area {
    background: #1a1b2e;
    border-top: 1px solid rgba(99, 102, 241, 0.2);
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 14px;
    color: var(--text-color);
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
}

[data-theme="dark"] .ai-chat-input {
    background: #0d0e1a;
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #e2e8f0;
}

[data-theme="dark"] .ai-chat-input::placeholder {
    color: #64748b;
}

.ai-chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.ai-chat-input::placeholder {
    color: var(--text-muted);
}

.ai-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send-btn:hover:not(:disabled) {
    background: var(--primary-dark, #4338ca);
    transform: scale(1.05);
}

.ai-chat-send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.ai-chat-send-btn.loading {
    background: var(--text-muted);
}

.ai-chat-send-btn.loading::after {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================
   CONTEXT INDICATOR
   ========================================== */

.ai-context-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--primary-color);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

[data-theme="dark"] .ai-context-indicator {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
}

[data-theme="dark"] .ai-context-indicator .symbol {
    color: #c7d2fe;
}

.ai-context-indicator .symbol {
    font-weight: 600;
}

.ai-context-clear {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}

.ai-context-clear:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ==========================================
   ACTION BUTTONS
   ========================================== */

.ai-chat-actions {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.ai-action-btn {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.ai-action-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ==========================================
   MARKDOWN CONTENT
   ========================================== */

.ai-chat-message.assistant .ai-markdown {
    line-height: 1.6;
}

.ai-chat-message.assistant .ai-markdown p {
    margin: 0 0 8px;
}

.ai-chat-message.assistant .ai-markdown p:last-child {
    margin-bottom: 0;
}

.ai-chat-message.assistant .ai-markdown strong {
    font-weight: 600;
    color: var(--primary-color);
}

.ai-chat-message.assistant .ai-markdown ul,
.ai-chat-message.assistant .ai-markdown ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chat-message.assistant .ai-markdown li {
    margin-bottom: 4px;
}

.ai-chat-message.assistant .ai-markdown code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Monaco', 'Menlo', monospace;
}

.ai-chat-message.assistant .ai-markdown pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-chat-message.assistant .ai-markdown pre code {
    background: none;
    padding: 0;
}

/* ==========================================
   FLOATING CHAT BUTTON (Alternative Mode)
   ========================================== */

.ai-chat-float-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark, #4338ca));
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s;
    z-index: 1000;
}

.ai-chat-float-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.ai-chat-float-btn.hidden {
    display: none;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .ai-chat-panel {
        height: 500px;
        border-radius: 8px;
    }

    .ai-chat-header {
        padding: 10px 12px;
    }

    .ai-chat-title {
        font-size: 14px;
    }

    .ai-model-badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    .ai-chat-body {
        padding: 12px;
    }

    .ai-chat-message {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 13px;
    }

    .ai-chat-input-area {
        padding: 10px 12px;
    }

    .ai-chat-input {
        padding: 10px 14px;
        font-size: 14px;
    }

    .ai-chat-send-btn {
        width: 40px;
        height: 40px;
    }
}

/* ==========================================
   ANALYSIS SECTION INTEGRATION
   ========================================== */

.stock-analysis-with-chat {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
}

.stock-analysis-with-chat .analysis-main {
    min-width: 0;
}

.stock-analysis-with-chat .ai-chat-sidebar {
    position: sticky;
    top: 20px;
    height: fit-content;
    max-height: calc(100vh - 120px);
}

@media (max-width: 1200px) {
    .stock-analysis-with-chat {
        grid-template-columns: 1fr;
    }

    .stock-analysis-with-chat .ai-chat-sidebar {
        position: relative;
        top: 0;
        max-height: 500px;
    }
}
