/**
 * AI Hub Styles
 * Modern, clean interface for AI-generated insights
 * Date: 2025-12-30
 */

/* ==================== Container ==================== */
.ai-hub-container {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

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

/* ==================== Header Section ==================== */
.ai-hub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color, #e0e0e0);
}

.hub-title-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hub-icon {
    font-size: 3rem;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.hub-title-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.hub-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary, #2C3E50);
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hub-tagline {
    margin: 0;
    font-size: 1rem;
    color: var(--text-secondary, #6c757d);
    font-weight: 400;
}

.hub-stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 12px;
    min-width: 100px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
}

/* ==================== Quick Actions Section ==================== */
.quick-actions-section {
    margin-bottom: 2.5rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary, #2C3E50);
    margin: 0 0 1rem 0;
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

@media (max-width: 900px) {
    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.action-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1.5rem;
    background: white;
    border: 2px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
}

.action-card:hover {
    border-color: var(--primary-purple, #8B7EC8);
    box-shadow: 0 4px 12px rgba(139, 126, 200, 0.15);
    transform: translateY(-2px);
}

.action-card:active {
    transform: translateY(0);
}

.action-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.action-label {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary, #2C3E50);
    margin-bottom: 0.5rem;
}

.action-desc {
    font-size: 0.875rem;
    color: var(--text-secondary, #6c757d);
    line-height: 1.4;
}

/* ==================== Insights Section ==================== */
.insights-section {
    margin-bottom: 2rem;
}

.insights-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary, #2C3E50);
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    border-color: var(--primary-purple, #8B7EC8);
    background: var(--bg-secondary, #f8f9fa);
}

.refresh-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.refresh-btn:active .refresh-icon {
    transform: rotate(180deg);
}

.insights-container {
    min-height: 300px;
}

/* ==================== Insights Grid ==================== */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1100px) {
    .insights-grid {
        grid-template-columns: 1fr;
    }
}

.insight-card {
    background: white;
    border: 2px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.insight-card:hover {
    border-color: var(--primary-purple, #8B7EC8);
    box-shadow: 0 4px 12px rgba(139, 126, 200, 0.15);
    transform: translateY(-2px);
}

.insight-card-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.insight-icon-large {
    font-size: 2rem;
    flex-shrink: 0;
}

.insight-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.insight-section {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-purple, #8B7EC8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insight-type-badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary, #6c757d);
    background: var(--bg-tertiary, #f0f0f0);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    text-transform: capitalize;
    width: fit-content;
}

.insight-time {
    font-size: 0.75rem;
    color: var(--text-secondary, #6c757d);
}

.insight-card-content {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-primary, #2C3E50);
    margin-bottom: 1rem;
}

.insight-response {
    display: flex;
    justify-content: flex-end;
}

.response-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #6c757d);
}

/* ==================== States ==================== */

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    min-height: 300px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-secondary, #f8f9fa);
    border-top-color: var(--primary-purple, #8B7EC8);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-state p {
    color: var(--text-secondary, #6c757d);
    font-size: 0.875rem;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    min-height: 300px;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary, #2C3E50);
    margin: 0 0 0.5rem 0;
}

.empty-state p {
    font-size: 1rem;
    color: var(--text-secondary, #6c757d);
    margin: 0 0 1.5rem 0;
    max-width: 500px;
    line-height: 1.6;
}

.empty-state .primary-button {
    margin-top: 0.5rem;
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    min-height: 300px;
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.error-state h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary, #2C3E50);
    margin: 0 0 0.5rem 0;
}

.error-state p {
    font-size: 1rem;
    color: var(--text-secondary, #6c757d);
    margin: 0 0 1.5rem 0;
    max-width: 500px;
}

/* ==================== Responsive Design ==================== */

@media (max-width: 768px) {
    .ai-hub-container {
        padding: 1.5rem;
    }

    .ai-hub-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.5rem;
    }

    .hub-title {
        font-size: 1.75rem;
    }

    .hub-stats {
        width: 100%;
        justify-content: space-around;
        gap: 1rem;
    }

    .stat-item {
        flex: 1;
        min-width: auto;
    }

    .quick-actions-grid {
        grid-template-columns: 1fr;
    }

    .insights-grid {
        grid-template-columns: 1fr;
    }

    .insights-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .refresh-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .ai-hub-container {
        padding: 1rem;
    }

    .hub-icon {
        font-size: 2.5rem;
    }

    .hub-title {
        font-size: 1.5rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .action-card {
        padding: 1.25rem;
    }

    .insight-card {
        padding: 1.25rem;
    }
}

/* ==================== Insight Detail Modal ==================== */

.insight-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.insight-modal-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

.insight-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 550px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.insight-modal-backdrop.visible .insight-modal {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.insight-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    background: linear-gradient(135deg, rgba(139, 126, 200, 0.1), rgba(127, 176, 105, 0.1));
}

.insight-modal-title {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.insight-modal-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.insight-modal-title h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--primary-purple, #8B7EC8);
    font-weight: 600;
}

.insight-modal-type {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary, #6c757d);
    background: var(--bg-tertiary, #f0f0f0);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    margin-top: 0.5rem;
}

.insight-modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--text-secondary, #6c757d);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.insight-modal-close:hover {
    color: var(--text-primary, #2C3E50);
}

.insight-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(80vh - 200px);
}

.insight-modal-content {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary, #2C3E50);
    margin: 0 0 1rem 0;
    white-space: pre-wrap;
}

.insight-modal-date {
    font-size: 0.8125rem;
    color: var(--text-secondary, #6c757d);
    margin: 0;
}

.insight-modal-actions {
    display: flex;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color, #e0e0e0);
    background: var(--bg-secondary, #f8f9fa);
}

.insight-action-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.insight-action-btn.primary {
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
    color: white;
}

.insight-action-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 126, 200, 0.4);
}

.insight-action-btn.secondary {
    background: white;
    color: var(--primary-purple, #8B7EC8);
    border: 2px solid var(--primary-purple, #8B7EC8);
}

.insight-action-btn.secondary:hover {
    background: rgba(139, 126, 200, 0.1);
}

.insight-action-btn.tertiary {
    background: transparent;
    color: var(--text-secondary, #6c757d);
    border: 1px solid var(--border-color, #e0e0e0);
}

.insight-action-btn.tertiary:hover {
    background: var(--bg-tertiary, #f0f0f0);
}

/* Insight card hover state */
.insight-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.insight-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-color: var(--primary-purple, #8B7EC8);
}

@media (max-width: 480px) {
    .insight-modal {
        width: 95%;
        max-height: 90vh;
    }

    .insight-modal-actions {
        flex-direction: column;
    }

    .insight-action-btn {
        width: 100%;
    }
}

/* ==================== Source Data Display ==================== */

.insight-source-data {
    margin: 1rem 0;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    overflow: hidden;
}

.source-data-toggle {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary, #f8f9fa);
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text-secondary, #6c757d);
    transition: background 0.2s ease;
}

.source-data-toggle:hover {
    background: var(--bg-tertiary, #e9ecef);
}

.source-data-content {
    padding: 1rem;
    background: white;
    max-height: 200px;
    overflow-y: auto;
}

.source-data-content.hidden {
    display: none;
}

.source-data-field {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.source-data-field:last-child {
    border-bottom: none;
}

.source-data-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-data-value {
    font-size: 0.875rem;
    color: var(--text-primary, #2C3E50);
    margin-top: 0.25rem;
}

/* Conversation badge */
.insight-conversation-badge {
    margin-left: 0.5rem;
    font-size: 0.875rem;
}

/* Discuss button styling */
.insight-action-btn.discuss {
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), #a594d8);
    color: white;
    border: none;
}

.insight-action-btn.discuss:hover {
    background: linear-gradient(135deg, #7a6db7, #9483c7);
}

/* ==================== Chat View ==================== */

.ai-hub-container.chat-mode {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    max-height: 800px;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
    border-radius: 12px 12px 0 0;
}

.chat-back-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s ease;
}

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

.chat-header-info h2 {
    margin: 0;
    font-size: 1.25rem;
    color: white;
}

.chat-context {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.8);
}

.chat-insight-summary {
    padding: 1rem 1.5rem;
    background: var(--bg-secondary, #f8f9fa);
    border-left: 4px solid var(--primary-purple, #8B7EC8);
}

.insight-preview {
    font-size: 0.875rem;
    color: var(--text-secondary, #6c757d);
    line-height: 1.5;
}

.insight-preview p {
    margin: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: white;
}

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

.chat-message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary, #e9ecef);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.chat-message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
}

.message-content {
    background: var(--bg-secondary, #f8f9fa);
    padding: 0.75rem 1rem;
    border-radius: 12px;
}

.chat-message.user .message-content {
    background: var(--primary-purple, #8B7EC8);
    color: white;
}

.message-content p {
    margin: 0;
    line-height: 1.5;
}

.message-time {
    display: block;
    font-size: 0.7rem;
    color: var(--text-tertiary, #adb5bd);
    margin-top: 0.25rem;
}

.chat-message.user .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Chat Welcome */
.chat-welcome {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
    margin: auto;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.chat-welcome h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary, #2C3E50);
}

.chat-welcome p {
    color: var(--text-secondary, #6c757d);
    margin-bottom: 1.5rem;
}

.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.suggested-question {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary, #6c757d);
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggested-question:hover {
    background: var(--primary-purple, #8B7EC8);
    border-color: var(--primary-purple, #8B7EC8);
    color: white;
}

/* Chat Input */
.chat-input-area {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary, #f8f9fa);
    border-top: 1px solid var(--border-color, #e0e0e0);
    border-radius: 0 0 12px 12px;
}

.chat-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    font-size: 0.875rem;
    resize: none;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-purple, #8B7EC8);
    box-shadow: 0 0 0 3px rgba(139, 126, 200, 0.15);
}

.chat-send-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-purple, #8B7EC8), var(--primary-green, #7FB069));
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 126, 200, 0.3);
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-tertiary, #adb5bd);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-6px);
    }
}

/* Chat Responsive */
@media (max-width: 768px) {
    .ai-hub-container.chat-mode {
        height: calc(100vh - 100px);
    }

    .chat-message {
        max-width: 95%;
    }

    .suggested-questions {
        flex-direction: column;
    }

    .suggested-question {
        width: 100%;
    }
}
