/* ═══════════════════════════════════════════════════════════════
   AI ANALYSIS — Insights modal, dashboard button, settings
   ═══════════════════════════════════════════════════════════════ */

/* --- Dashboard AI Button --- */

.ai-dashboard-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px 24px;
    background: linear-gradient(135deg, #5856d6, #af52de);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(88, 86, 214, 0.3);
}

.ai-dashboard-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(88, 86, 214, 0.4);
    filter: brightness(1.1);
}

.ai-dashboard-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(88, 86, 214, 0.3);
}

.ai-dashboard-btn-icon {
    font-size: 1.1em;
}

[data-theme="dark"] .ai-dashboard-btn {
    box-shadow: 0 2px 12px rgba(88, 86, 214, 0.4);
}

[data-theme="dark"] .ai-dashboard-btn:hover {
    box-shadow: 0 4px 20px rgba(88, 86, 214, 0.5);
}

/* --- AI Insights Modal --- */

.ai-insights-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-insights-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.ai-insights-modal {
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl);
    width: 90vw;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    transform: scale(0.95);
    transition: transform 0.3s ease;
    overflow: hidden;
}

.ai-insights-overlay.show .ai-insights-modal {
    transform: scale(1);
}

.ai-insights-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-light);
}

.ai-insights-title {
    font-size: var(--text-heading);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.ai-insights-subtitle {
    font-size: var(--text-small);
    color: var(--text-secondary);
    margin-top: 2px;
}

.ai-insights-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-insights-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* --- Tabs --- */

.ai-tabs {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-xl);
    border-bottom: 1px solid var(--border-light);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ai-tab-btn {
    flex-shrink: 0;
    padding: var(--space-xs) var(--space-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-small);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.ai-tab-btn.active {
    background: linear-gradient(135deg, #5856d6, #af52de);
    color: white;
    border-color: transparent;
}

/* --- Content area --- */

.ai-insights-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg) var(--space-xl);
    min-height: 200px;
}

/* Type header */
.ai-type-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.ai-type-icon {
    font-size: 2rem;
}

.ai-type-title {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.ai-type-desc {
    font-size: var(--text-small);
    color: var(--text-secondary);
}

/* Analyze button */
.ai-analyze-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    justify-content: center;
}

.ai-analyze-btn-icon {
    font-size: 1.1em;
}

/* Custom question */
.ai-custom-question {
    margin-bottom: var(--space-lg);
}

.ai-custom-label {
    display: block;
    font-size: var(--text-small);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.ai-custom-textarea {
    width: 100%;
    padding: var(--space-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-body);
    resize: vertical;
    min-height: 80px;
    margin-bottom: var(--space-md);
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.ai-custom-textarea:focus {
    outline: none;
    border-color: #5856d6;
    box-shadow: 0 0 0 3px rgba(88, 86, 214, 0.15);
}

/* Result area */
.ai-result {
    display: none;
    margin-top: var(--space-lg);
    animation: aiFadeIn 0.3s ease;
}

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

.ai-response {
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    font-size: var(--text-body);
    line-height: 1.6;
    color: var(--text-primary);
}

.ai-response h2,
.ai-response h3,
.ai-response h4 {
    margin-top: var(--space-md);
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.ai-response h2 { font-size: var(--text-heading); }
.ai-response h3 { font-size: var(--text-body); font-weight: var(--font-semibold); }
.ai-response h4 { font-size: var(--text-small); font-weight: var(--font-semibold); }

.ai-response ul {
    padding-left: var(--space-lg);
    margin: var(--space-sm) 0;
}

.ai-response li {
    margin-bottom: var(--space-xs);
}

.ai-response strong {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
}

.ai-response p {
    margin-bottom: var(--space-sm);
}

.ai-result-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-md);
}

/* Error state */
.ai-error {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: rgba(255, 59, 48, 0.08);
    border: 1px solid rgba(255, 59, 48, 0.2);
    border-radius: var(--radius-lg);
    color: var(--danger);
}

.ai-error-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.ai-error-message {
    font-size: var(--text-small);
}

/* Loading state */
.ai-loading {
    text-align: center;
    padding: var(--space-xl) 0;
    color: var(--text-secondary);
}

.ai-loading p {
    margin-top: var(--space-md);
    font-size: var(--text-small);
}

.ai-loading-dots {
    display: inline-flex;
    gap: 6px;
}

.ai-loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #5856d6;
    animation: aiDotPulse 1.4s ease-in-out infinite;
}

.ai-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiDotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Spinner for button */
.ai-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: aiSpin 0.6s linear infinite;
}

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

/* Setup prompt */
.ai-setup-prompt {
    text-align: center;
    padding: var(--space-xl) var(--space-lg);
}

.ai-setup-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
}

.ai-setup-prompt h3 {
    font-size: var(--text-heading);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.ai-setup-prompt p {
    font-size: var(--text-body);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.ai-setup-detail {
    font-size: var(--text-small) !important;
    color: var(--text-tertiary) !important;
}

.ai-setup-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
    margin-top: var(--space-lg);
}

/* --- Settings: API Key --- */

.ai-key-status {
    display: inline-block;
    padding: 2px var(--space-sm);
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    font-weight: var(--font-medium);
}

.ai-key-status.configured {
    background: rgba(52, 199, 89, 0.12);
    color: var(--success);
}

.ai-key-status.not-configured {
    background: rgba(255, 149, 0, 0.12);
    color: var(--warning);
}

.ai-key-input-row {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

.ai-key-input {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: var(--text-small);
    min-width: 0;
}

.ai-key-input:focus {
    outline: none;
    border-color: #5856d6;
    box-shadow: 0 0 0 3px rgba(88, 86, 214, 0.15);
}

.ai-key-toggle-btn,
.ai-key-clear-btn {
    flex-shrink: 0;
    padding: var(--space-xs) var(--space-sm) !important;
    font-size: var(--text-caption) !important;
    min-width: auto !important;
}

/* --- Export modal: AI option --- */

.export-ai-icon {
    color: #5856d6;
}

[data-theme="dark"] .export-ai-icon {
    color: #7d7aff;
}

/* --- Responsive --- */

@media (max-width: 480px) {
    .ai-insights-modal {
        width: 95vw;
        max-height: 90vh;
    }

    .ai-insights-header {
        padding: var(--space-md) var(--space-lg);
    }

    .ai-tabs {
        padding: var(--space-sm) var(--space-md);
    }

    .ai-insights-content {
        padding: var(--space-md) var(--space-lg);
    }

    .ai-setup-actions {
        flex-direction: column;
    }
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Analysis Type Grid
   ═══════════════════════════════════════════════════════════════ */

.ai-type-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
}

.ai-type-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.ai-type-card:hover {
    background: var(--bg-tertiary);
    border-color: #5856d6;
    transform: translateY(-1px);
}

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

.ai-type-card-icon {
    font-size: 1.6rem;
    flex-shrink: 0;
    line-height: 1;
}

.ai-type-card-body {
    min-width: 0;
}

.ai-type-card-label {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.ai-type-card-desc {
    font-size: var(--text-caption);
    color: var(--text-secondary);
    line-height: 1.3;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Analysis View Header / Back Button
   ═══════════════════════════════════════════════════════════════ */

.ai-view-header {
    margin-bottom: var(--space-md);
}

.ai-back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    font-size: var(--text-small);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

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

.ai-analysis-hero {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) 0 var(--space-lg);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-lg);
}

.ai-type-icon-large {
    font-size: 2.4rem;
    line-height: 1;
    flex-shrink: 0;
}

.ai-type-title-large {
    font-size: var(--text-heading);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.ai-type-desc-large {
    font-size: var(--text-small);
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Structured Response: Scorecard
   ═══════════════════════════════════════════════════════════════ */

.ai-scorecard {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    margin-bottom: var(--space-lg);
}

.ai-score-circle-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.ai-score-svg {
    display: block;
}

.ai-score-label {
    font-size: var(--text-caption);
    font-weight: var(--font-semibold);
    color: var(--text-secondary);
    margin-top: var(--space-xs);
    text-align: center;
}

.ai-metrics-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    flex: 1;
}

.ai-metric-pill {
    display: flex;
    flex-direction: column;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    min-width: 100px;
}

.ai-metric-name {
    font-size: var(--text-caption);
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.ai-metric-value {
    font-size: var(--text-small);
    font-weight: var(--font-semibold);
}

.ai-metric-good {
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.2);
}
.ai-metric-good .ai-metric-value { color: var(--success); }

.ai-metric-warning {
    background: rgba(255, 149, 0, 0.1);
    border: 1px solid rgba(255, 149, 0, 0.2);
}
.ai-metric-warning .ai-metric-value { color: var(--warning); }

.ai-metric-danger {
    background: rgba(255, 59, 48, 0.1);
    border: 1px solid rgba(255, 59, 48, 0.2);
}
.ai-metric-danger .ai-metric-value { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Structured Response: Charts
   ═══════════════════════════════════════════════════════════════ */

.ai-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.ai-chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
}

.ai-chart-title {
    font-size: var(--text-small);
    font-weight: var(--font-semibold);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
    text-align: center;
}

.ai-chart-wrap {
    position: relative;
    width: 100%;
}

.ai-chart-canvas-wrap {
    position: relative;
    width: 100%;
}

.ai-chart-error {
    text-align: center;
    color: var(--text-tertiary);
    font-size: var(--text-caption);
    padding: var(--space-lg) 0;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Structured Response: Recommendations
   ═══════════════════════════════════════════════════════════════ */

.ai-section-heading {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.ai-recommendations {
    margin-bottom: var(--space-lg);
}

.ai-recommendation {
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    border-left: 3px solid transparent;
    background: var(--bg-secondary);
    margin-bottom: var(--space-sm);
}

.ai-rec-high {
    border-left-color: var(--danger);
    background: rgba(255, 59, 48, 0.04);
}

.ai-rec-medium {
    border-left-color: var(--warning);
    background: rgba(255, 149, 0, 0.04);
}

.ai-rec-low {
    border-left-color: var(--success);
    background: rgba(52, 199, 89, 0.04);
}

.ai-rec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xs);
}

.ai-rec-priority {
    font-size: var(--text-caption);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.ai-rec-high .ai-rec-priority { color: var(--danger); }
.ai-rec-medium .ai-rec-priority { color: var(--warning); }
.ai-rec-low .ai-rec-priority { color: var(--success); }

.ai-rec-savings {
    font-size: var(--text-caption);
    font-weight: var(--font-semibold);
    color: var(--success);
    background: rgba(52, 199, 89, 0.1);
    padding: 2px var(--space-sm);
    border-radius: var(--radius-full);
}

.ai-rec-title {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: 4px;
}

.ai-rec-desc {
    font-size: var(--text-small);
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Structured Response: Narrative
   ═══════════════════════════════════════════════════════════════ */

.ai-narrative {
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    line-height: 1.6;
    font-size: var(--text-small);
    color: var(--text-primary);
}

.ai-narrative h2 { font-size: var(--text-heading); font-weight: var(--font-bold); margin: var(--space-md) 0 var(--space-sm); }
.ai-narrative h3 { font-size: var(--text-body); font-weight: var(--font-semibold); margin: var(--space-md) 0 var(--space-xs); }
.ai-narrative h4 { font-size: var(--text-small); font-weight: var(--font-semibold); margin: var(--space-sm) 0 var(--space-xs); }
.ai-narrative ul, .ai-narrative ol { padding-left: var(--space-lg); margin: var(--space-sm) 0; }
.ai-narrative li { margin-bottom: var(--space-xs); }
.ai-narrative p { margin-bottom: var(--space-sm); }
.ai-narrative strong { font-weight: var(--font-semibold); color: var(--text-primary); }
.ai-narrative code { font-family: monospace; font-size: 0.9em; background: var(--bg-primary); padding: 1px 4px; border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Chat Mode
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 300px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-sm) 0 var(--space-md);
    -webkit-overflow-scrolling: touch;
}

.ai-bubble {
    max-width: 90%;
}

.ai-bubble-user {
    align-self: flex-end;
}

.ai-bubble-assistant {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
}

.ai-bubble-error {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(255, 59, 48, 0.08);
    border: 1px solid rgba(255, 59, 48, 0.2);
    border-radius: var(--radius-lg);
    max-width: 90%;
}

.ai-bubble-user .ai-bubble-text {
    padding: var(--space-sm) var(--space-md);
    background: linear-gradient(135deg, #5856d6, #0071e3);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
    font-size: var(--text-small);
    line-height: 1.5;
    word-break: break-word;
}

.ai-bubble-error .ai-bubble-text {
    font-size: var(--text-small);
    color: var(--danger);
}

.ai-bubble-content {
    width: 100%;
}

.ai-chat-input-row {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-md);
}

.ai-custom-textarea {
    flex: 1;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: var(--text-small);
    color: var(--text-primary);
    resize: none;
    line-height: 1.5;
    transition: border-color 0.15s;
}

.ai-custom-textarea:focus {
    outline: none;
    border-color: #5856d6;
    box-shadow: 0 0 0 2px rgba(88, 86, 214, 0.12);
}

.ai-chat-send-btn {
    flex-shrink: 0;
    padding: var(--space-sm) var(--space-md) !important;
    height: 40px;
    white-space: nowrap;
}

.ai-chat-hint {
    font-size: var(--text-caption);
    color: var(--text-tertiary);
    text-align: right;
    margin-top: 4px;
}

/* Follow-up suggestion chips */
.ai-follow-up-chips {
    padding: var(--space-sm) 0;
}

.ai-follow-up-label {
    font-size: var(--text-caption);
    color: var(--text-tertiary);
    margin-bottom: var(--space-xs);
}

.ai-follow-up-chip {
    display: inline-block;
    margin: 2px 4px 4px 0;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    text-align: left;
    line-height: 1.4;
}

.ai-follow-up-chip:hover {
    background: rgba(88, 86, 214, 0.08);
    border-color: #5856d6;
    color: #5856d6;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Provider Badge
   ═══════════════════════════════════════════════════════════════ */

.ai-provider-badge {
    display: inline-block;
    padding: 3px var(--space-sm);
    background: rgba(88, 86, 214, 0.08);
    border: 1px solid rgba(88, 86, 214, 0.15);
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    font-weight: var(--font-medium);
    color: #5856d6;
    margin-bottom: var(--space-md);
}

[data-theme="dark"] .ai-provider-badge {
    background: rgba(125, 122, 255, 0.12);
    border-color: rgba(125, 122, 255, 0.2);
    color: #7d7aff;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Action Bar
   ═══════════════════════════════════════════════════════════════ */

.ai-action-bar {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-light);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Score Arc Animation
   ═══════════════════════════════════════════════════════════════ */

.ai-score-arc {
    transition: stroke-dashoffset 1s ease-out;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Skeleton Loading
   ═══════════════════════════════════════════════════════════════ */

.ai-skeleton-container {
    animation: aiFadeIn 0.3s ease;
}

.ai-skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: aiShimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes aiShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ai-skeleton-scorecard {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    margin-bottom: var(--space-lg);
}

.ai-skeleton-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ai-skeleton-metrics-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    flex: 1;
}

.ai-skeleton-pill {
    width: 100px;
    height: 44px;
    border-radius: var(--radius-md);
}

.ai-skeleton-chart {
    width: 100%;
    height: 200px;
    margin-bottom: var(--space-lg);
    border-radius: var(--radius-lg);
}

.ai-skeleton-recs {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.ai-skeleton-rec {
    height: 72px;
    border-radius: var(--radius-lg);
}

.ai-skeleton-text {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.ai-skeleton-line {
    height: 14px;
    border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Chat Input Area
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-input-area {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-md);
}

.ai-chat-input {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: var(--text-small);
    color: var(--text-primary);
    resize: none;
    line-height: 1.5;
    max-height: 120px;
    transition: border-color 0.15s;
}

.ai-chat-input:focus {
    outline: none;
    border-color: #5856d6;
    box-shadow: 0 0 0 2px rgba(88, 86, 214, 0.12);
}

.ai-chat-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #5856d6, #af52de);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, opacity 0.15s;
}

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

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Chat Welcome
   ═══════════════════════════════════════════════════════════════ */

.ai-chat-welcome {
    text-align: center;
    padding: var(--space-xl) var(--space-lg);
    color: var(--text-secondary);
}

.ai-chat-welcome-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-md);
}

.ai-chat-welcome p {
    font-size: var(--text-small);
    margin-bottom: var(--space-lg);
    line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Suggestion Chips
   ═══════════════════════════════════════════════════════════════ */

.ai-suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    justify-content: center;
    padding: var(--space-sm) 0;
}

.ai-chip {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    line-height: 1.4;
}

.ai-chip:hover {
    background: rgba(88, 86, 214, 0.08);
    border-color: #5856d6;
    color: #5856d6;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Chat Bubble Content
   ═══════════════════════════════════════════════════════════════ */

.ai-bubble-content {
    width: 100%;
    font-size: var(--text-small);
    line-height: 1.6;
    color: var(--text-primary);
}

.ai-bubble-content h2, .ai-bubble-content h3, .ai-bubble-content h4 {
    margin-top: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.ai-bubble-content ul, .ai-bubble-content ol {
    padding-left: var(--space-lg);
    margin: var(--space-xs) 0;
}

.ai-bubble-content li { margin-bottom: 2px; }
.ai-bubble-content p { margin-bottom: var(--space-xs); }
.ai-bubble-content strong { font-weight: var(--font-semibold); }

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Error inline (chat)
   ═══════════════════════════════════════════════════════════════ */

.ai-error-inline {
    color: var(--danger);
    font-size: var(--text-small);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Disclaimer
   ═══════════════════════════════════════════════════════════════ */

.ai-disclaimer {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-md);
    margin-top: var(--space-lg);
    background: rgba(88, 86, 214, 0.04);
    border: 1px solid rgba(88, 86, 214, 0.1);
    border-radius: var(--radius-lg);
    font-size: var(--text-caption);
    color: var(--text-secondary);
    line-height: 1.5;
}

.ai-disclaimer svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: #5856d6;
}

.ai-disclaimer strong {
    display: block;
    font-size: var(--text-small);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: 4px;
}

.ai-disclaimer p {
    margin: 0;
}

.ai-chat-disclaimer {
    font-size: var(--text-caption);
    color: var(--text-tertiary);
    margin-top: var(--space-md);
    line-height: 1.4;
}

[data-theme="dark"] .ai-disclaimer {
    background: rgba(125, 122, 255, 0.06);
    border-color: rgba(125, 122, 255, 0.12);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Responsive overrides (mobile)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .ai-type-grid {
        grid-template-columns: 1fr;
    }

    .ai-scorecard {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }

    .ai-score-circle-wrap {
        flex-direction: row;
        gap: var(--space-md);
        align-items: center;
    }

    .ai-score-label {
        margin-top: 0;
    }

    .ai-charts-grid {
        grid-template-columns: 1fr;
    }

    .ai-skeleton-scorecard {
        flex-direction: column;
    }

    .ai-skeleton-circle {
        width: 80px;
        height: 80px;
    }

    .ai-suggestion-chips {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Dashboard Button Loading State
   ═══════════════════════════════════════════════════════════════ */

.ai-btn-loading {
    position: relative;
    pointer-events: none;
}

.ai-btn-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(255,255,255,0) 60%);
    animation: aiBtnPulse 1.5s ease-in-out infinite;
}

@keyframes aiBtnPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Copy Button Feedback
   ═══════════════════════════════════════════════════════════════ */

.ai-copied {
    color: var(--success) !important;
    border-color: var(--success) !important;
    transition: color 0.2s, border-color 0.2s;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Error Hint
   ═══════════════════════════════════════════════════════════════ */

.ai-error-hint {
    font-size: var(--text-caption);
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: var(--font-medium);
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Send Button Disabled State
   ═══════════════════════════════════════════════════════════════ */

.ai-send-disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Chart Fade-in (initial hidden state)
   ═══════════════════════════════════════════════════════════════ */

.ai-chart-card {
    will-change: opacity, transform;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Score Ring Color Grades
   ═══════════════════════════════════════════════════════════════ */

@keyframes aiScoreArcDraw {
    from { stroke-dashoffset: 339.29; }
}

.ai-score-arc {
    animation: aiScoreArcDraw 1s ease-out forwards;
    transition: stroke-dashoffset 1s ease-out, stroke 0.3s ease;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Typing Indicator Enhancement
   ═══════════════════════════════════════════════════════════════ */

.ai-bubble-assistant .ai-loading-dots {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
    border: 1px solid var(--border-light);
    display: inline-flex;
}

/* ═══════════════════════════════════════════════════════════════
   AI Insights — Keyboard Shortcut Hint
   ═══════════════════════════════════════════════════════════════ */

.ai-kbd-hint {
    font-size: var(--text-caption);
    color: var(--text-tertiary);
    text-align: center;
    margin-top: var(--space-sm);
}

.ai-kbd-hint kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85em;
    color: var(--text-secondary);
}


/* ═══════════════════════════════════════════════════════════════
   AI FINANCIAL LITERACY TIPS
   ═══════════════════════════════════════════════════════════════ */

.ai-tips-section {
    margin-top: var(--space-md);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.ai-tips-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: rgba(52, 199, 89, 0.08);
    border: 1px solid rgba(52, 199, 89, 0.15);
    border-radius: var(--radius-lg);
    cursor: pointer;
    color: var(--text-primary);
    font-size: var(--text-small);
    font-weight: var(--font-semibold);
    transition: all 0.2s ease;
    text-align: left;
}

.ai-tips-toggle:hover {
    background: rgba(52, 199, 89, 0.12);
}

.ai-tips-toggle .tips-chevron {
    margin-left: auto;
    transition: transform 0.2s ease;
    font-size: 12px;
    color: var(--text-secondary);
}

.ai-tips-toggle.expanded .tips-chevron {
    transform: rotate(180deg);
}

.ai-tips-content {
    display: none;
    padding: var(--space-sm) var(--space-md);
    background: rgba(52, 199, 89, 0.04);
    border: 1px solid rgba(52, 199, 89, 0.1);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.ai-tips-content.show {
    display: block;
}

.ai-tip-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-xs);
    padding: var(--space-xs) 0;
    font-size: var(--text-small);
    color: var(--text-secondary);
    line-height: 1.5;
}

.ai-tip-item + .ai-tip-item {
    border-top: 1px solid rgba(52, 199, 89, 0.08);
}

.ai-tip-icon {
    flex-shrink: 0;
    font-size: 14px;
    margin-top: 1px;
}

[data-theme="dark"] .ai-tips-toggle {
    background: rgba(52, 199, 89, 0.12);
    border-color: rgba(52, 199, 89, 0.2);
}

[data-theme="dark"] .ai-tips-content {
    background: rgba(52, 199, 89, 0.06);
    border-color: rgba(52, 199, 89, 0.15);
}

