/**
 * Analytics Module Styles
 * Dashboard layout, metrics cards, charts, and AI chat interface
 */

/* Container */
.analytics-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

/* Header */
.analytics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-title h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.header-icon {
    color: var(--accent-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.time-selector {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.time-selector:focus {
    outline: none;
    border-color: var(--accent-color);
}

.btn-refresh {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-refresh:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Main Layout */
.analytics-layout {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    flex: 1;
    overflow: hidden;
}

/* Metrics Sidebar */
.metrics-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    background: var(--bg-secondary);
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
}

.metric-card:hover {
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.metric-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    flex-shrink: 0;
}

.metric-icon.messages {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.metric-icon.sessions {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.metric-icon.response {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.metric-icon.tokens {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.metric-icon.storage {
    background: rgba(6, 182, 212, 0.15);
    color: #06b6d4;
}

.metric-icon.errors {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.metric-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Content */
.analytics-main {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow-y: auto;
    gap: 1rem;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.chart-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.chart-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.chart-actions {
    display: flex;
    gap: 0.25rem;
}

.chart-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.chart-btn:hover {
    background: var(--bg-hover);
}

.chart-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.chart-container {
    height: 200px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* AI Analytics Chat */
.analytics-chat-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.chat-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0;
}

.chat-hint {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-messages {
    flex: 1;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
}

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

.message-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    flex-shrink: 0;
}

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

.message-content {
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-radius: 12px;
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.5;
}

.chat-message.user .message-content {
    background: var(--accent-color);
    color: white;
}

.message-content p {
    margin: 0 0 0.5rem 0;
}

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

.suggestion-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
}

.suggestion-list li {
    padding: 0.5rem 0.75rem;
    margin: 0.25rem 0;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8125rem;
}

.suggestion-list li:hover {
    background: var(--bg-hover);
    color: var(--accent-color);
}

.chat-input-container {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    padding: 0.625rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

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

.chat-send-btn:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

/* Analytics Results */
.analytics-results {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.metric-result {
    padding: 0.25rem 0;
    font-size: 0.8125rem;
}

.insight {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: rgba(34, 197, 94, 0.1);
    border-left: 3px solid #22c55e;
    border-radius: 4px;
    color: var(--text-secondary);
}

/* Activity Sidebar */
.activity-sidebar {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    background: var(--bg-secondary);
}

.activity-sidebar h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 1rem 0;
}

.activity-sidebar h3.mt-4 {
    margin-top: 1.5rem;
}

.activity-feed,
.top-queries {
    flex: 1;
    min-height: 0;
}

.activity-loading {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 1200px) {
    .analytics-layout {
        grid-template-columns: 200px 1fr;
    }
    
    .activity-sidebar {
        display: none;
    }
}

@media (max-width: 900px) {
    .analytics-layout {
        grid-template-columns: 1fr;
    }
    
    .metrics-sidebar {
        display: none;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .analytics-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: flex-end;
    }
}
