/**
 * Chat Charts Styling
 * Beautiful, modern data visualization styles for Intellisea chat
 */

/* ============================================
   CHART CONTAINER
   ============================================ */

.chat-chart-container {
    position: relative;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid rgba(14, 19, 105, 0.1);
    border-radius: 16px;
    padding: 24px;
    margin: 16px 0;
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.05),
        0 2px 4px -1px rgba(0, 0, 0, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.chat-chart-container:hover {
    box-shadow: 
        0 10px 25px -5px rgba(14, 19, 105, 0.1),
        0 4px 10px -3px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
}

/* Fullscreen mode */
.chat-chart-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    border-radius: 0;
    margin: 0;
    padding: 20px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.chat-chart-container.fullscreen .chart-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    height: auto;
}

.chat-chart-container.fullscreen canvas {
    max-height: 75vh !important;
    width: 100% !important;
}

.chat-chart-container.fullscreen .chart-insights {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 15px;
}

.chat-chart-container.fullscreen .insight-pill {
    padding: 8px 14px;
    font-size: 13px;
}

.chat-chart-container.fullscreen .chart-controls {
    flex-direction: row;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
}

/* Fullscreen close hint */
.chat-chart-container.fullscreen::after {
    content: 'Press ESC or tap ✕ to close';
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #9ca3af;
    opacity: 0.7;
}

/* Mobile fullscreen adjustments */
@media (max-width: 768px) {
    .chat-chart-container.fullscreen {
        padding: 15px;
    }
    
    .chat-chart-container.fullscreen .chart-wrapper {
        min-height: 50vh;
    }
    
    .chat-chart-container.fullscreen canvas {
        max-height: 60vh !important;
    }
    
    .chat-chart-container.fullscreen::after {
        content: 'Tap ✕ to close';
    }
}

/* ============================================
   CHART HEADER
   ============================================ */

.chart-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(14, 19, 105, 0.08);
}

.chart-title {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: #0e1369;
    margin: 0 0 4px 0;
    letter-spacing: -0.02em;
}

.chart-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: #6b7280;
    margin: 0;
    font-weight: 400;
}

/* ============================================
   CHART WRAPPER
   ============================================ */

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 300px;
}

.chart-wrapper canvas {
    width: 100% !important;
    max-width: 100%;
}

/* ============================================
   CHART ACTIONS
   ============================================ */

.chart-actions {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-chart-container:hover .chart-actions,
.chat-chart-container.fullscreen .chart-actions {
    opacity: 1;
}

.chart-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(14, 19, 105, 0.08);
    color: #0e1369;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chart-action-btn:hover {
    background: #0e1369;
    color: white;
    transform: scale(1.05);
}

.chart-action-btn i {
    font-size: 14px;
}

/* ============================================
   KPI CARDS
   ============================================ */

.chat-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.chat-kpi-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid rgba(14, 19, 105, 0.1);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.chat-kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 8px 20px -4px rgba(14, 19, 105, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.kpi-content {
    flex: 1;
}

.kpi-value {
    font-family: 'Inter', sans-serif;
    font-size: 28px;
    font-weight: 800;
    color: #0e1369;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.kpi-label {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: #6b7280;
    margin-top: 4px;
    font-weight: 500;
}

.kpi-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 20px;
    margin-top: 8px;
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
}

.kpi-change.positive {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.kpi-change.negative {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.kpi-change i {
    font-size: 10px;
}

.kpi-sparkline {
    width: 80px;
    height: 40px;
    margin-left: 16px;
}

.kpi-sparkline canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================
   CHART TYPE SPECIFIC STYLES
   ============================================ */

/* Line chart specific */
.chat-chart-container[data-type="line"] {
    background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
    border-color: rgba(16, 185, 129, 0.2);
}

/* Bar chart specific */
.chat-chart-container[data-type="bar"] {
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
    border-color: rgba(59, 130, 246, 0.2);
}

/* Pie/Doughnut chart specific */
.chat-chart-container[data-type="pie"],
.chat-chart-container[data-type="doughnut"] {
    background: linear-gradient(135deg, #fef3c7 0%, #ffffff 100%);
    border-color: rgba(245, 158, 11, 0.2);
}

/* Radar chart specific */
.chat-chart-container[data-type="radar"] {
    background: linear-gradient(135deg, #f3e8ff 0%, #ffffff 100%);
    border-color: rgba(139, 92, 246, 0.2);
}

/* ============================================
   LOADING STATE
   ============================================ */

.chat-chart-container.loading {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-chart-container.loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid rgba(14, 19, 105, 0.1);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: chart-spin 1s linear infinite;
}

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

/* ============================================
   COMPARISON CHART (BEFORE/AFTER)
   ============================================ */

.chart-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 16px 0;
}

.chart-comparison .chat-chart-container {
    margin: 0;
}

.chart-comparison-label {
    position: absolute;
    top: 12px;
    left: 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: 20px;
}

.chart-comparison-label.before {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.chart-comparison-label.after {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

/* ============================================
   METRIC BADGES
   ============================================ */

.chart-metric-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(14, 19, 105, 0.08);
}

.chart-metric-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(14, 19, 105, 0.05);
    color: #374151;
}

.chart-metric-badge .metric-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chart-metric-badge .metric-value {
    font-weight: 700;
    color: #0e1369;
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .chat-chart-container {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .chart-title {
        color: #f1f5f9;
    }

    .chart-subtitle {
        color: #94a3b8;
    }

    .chart-action-btn {
        background: rgba(255, 255, 255, 0.1);
        color: #e2e8f0;
    }

    .chart-action-btn:hover {
        background: #10b981;
        color: white;
    }

    .chat-kpi-card {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .kpi-value {
        color: #f1f5f9;
    }

    .kpi-label {
        color: #94a3b8;
    }
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 768px) {
    .chat-chart-container {
        padding: 16px;
        margin: 12px 0;
    }

    .chart-title {
        font-size: 16px;
    }

    .chart-wrapper {
        min-height: 200px;
    }

    .chat-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .chat-kpi-card {
        padding: 16px;
    }

    .kpi-value {
        font-size: 22px;
    }

    .kpi-sparkline {
        display: none;
    }

    .chart-actions {
        opacity: 1;
    }

    .chart-comparison {
        grid-template-columns: 1fr;
    }
}

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

    .chart-actions {
        top: 8px;
        right: 8px;
    }

    .chart-action-btn {
        width: 32px;
        height: 32px;
    }
}

/* ============================================
   ANIMATION EFFECTS
   ============================================ */

.chat-chart-container {
    animation: chartFadeIn 0.4s ease-out;
}

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

.chat-kpi-card {
    animation: kpiFadeIn 0.5s ease-out;
    animation-fill-mode: both;
}

.chat-kpi-card:nth-child(1) { animation-delay: 0.1s; }
.chat-kpi-card:nth-child(2) { animation-delay: 0.2s; }
.chat-kpi-card:nth-child(3) { animation-delay: 0.3s; }
.chat-kpi-card:nth-child(4) { animation-delay: 0.4s; }

@keyframes kpiFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .chat-chart-container {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #e5e7eb;
    }

    .chart-actions {
        display: none;
    }
}

/* ============================================
   RESPONSE TITLE (displays BEFORE chart)
   ============================================ */

.response-title {
    margin-bottom: 16px;
}

.response-title h1,
.response-title h2,
.response-title h3,
.response-title h4,
.response-title p,
.response-title strong {
    margin: 0;
    padding: 0;
}

/* ============================================
   AUTO-GENERATED CHARTS (displays AFTER title, BEFORE table)
   ============================================ */

.auto-generated-chart {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px dashed rgba(14, 19, 105, 0.15);
}

.auto-generated-chart .chat-chart-container {
    margin: 0;
}

/* Remove the "Interactive Visualization" label since title is now shown above */
.auto-generated-chart::before {
    display: none;
}

/* Zoom hint styling */
.chart-zoom-hint {
    text-align: center;
    padding: 8px 12px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(14, 19, 105, 0.05) 100%);
    border-radius: 0 0 12px 12px;
    margin-top: -4px;
}

.chart-zoom-hint small {
    color: #64748b;
    font-size: 11px;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.02em;
}

/* On mobile, show simpler hint */
@media (max-width: 768px) {
    .chart-zoom-hint small {
        font-size: 10px;
    }
    
    .chart-zoom-hint::before {
        content: '📱 ';
    }
}

/* ============================================
   SMART VIZ CHARTS
   ============================================ */

.smart-viz-chart {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

/* Insights Bar */
.chart-insights {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(14, 19, 105, 0.08);
}

.insight-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(135deg, 
        rgba(var(--accent-color-rgb, 16, 185, 129), 0.08) 0%,
        rgba(var(--accent-color-rgb, 16, 185, 129), 0.04) 100%);
    border: 1px solid rgba(var(--accent-color-rgb, 16, 185, 129), 0.2);
    border-radius: 24px;
    font-size: 13px;
    transition: all 0.2s ease;
}

.insight-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.insight-icon {
    font-size: 14px;
}

.insight-label {
    color: #374151;
    font-weight: 500;
}

.insight-value {
    font-weight: 700;
    color: var(--accent-color, #10b981);
}

/* Controls Bar */
.chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(14, 19, 105, 0.08);
}

.chart-type-selector {
    display: flex;
    gap: 4px;
    background: rgba(14, 19, 105, 0.04);
    padding: 4px;
    border-radius: 10px;
}

.chart-type-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chart-type-btn:hover {
    background: rgba(14, 19, 105, 0.08);
    color: #0e1369;
}

.chart-type-btn.active {
    background: #0e1369;
    color: white;
    box-shadow: 0 2px 8px rgba(14, 19, 105, 0.3);
}

.chart-type-btn i {
    font-size: 14px;
}

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

/* Smart chart specific hover effect */
.smart-viz-chart:hover {
    box-shadow: 
        0 12px 28px -8px rgba(14, 19, 105, 0.12),
        0 4px 10px -3px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* Loading state for smart charts */
.smart-viz-chart.loading {
    position: relative;
}

.smart-viz-chart.loading::before {
    content: 'Analyzing data...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

.smart-viz-chart.loading::after {
    content: '';
    position: absolute;
    top: calc(50% + 30px);
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(14, 19, 105, 0.1);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: chart-spin 1s linear infinite;
}

/* Smart Viz Loading State */
.smart-viz-loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    border: 1px dashed rgba(14, 19, 105, 0.2);
    border-radius: 16px;
}

.smart-viz-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
}

.loader-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(14, 19, 105, 0.1);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: chart-spin 0.8s linear infinite;
}

/* Responsive for smart charts */
@media (max-width: 768px) {
    .chat-chart-container {
        padding: 16px;
        margin: 12px 0;
    }
    
    .chart-wrapper {
        height: 280px;
        min-height: 280px;
    }
    
    .chart-wrapper canvas {
        height: 100% !important;
    }
    
    .chart-insights {
        gap: 6px;
        flex-wrap: wrap;
    }
    
    .insight-pill {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .chart-controls {
        flex-direction: column;
        gap: 12px;
    }
    
    .chart-type-selector {
        width: 100%;
        justify-content: center;
    }
    
    .chart-actions-inline {
        width: 100%;
        justify-content: center;
    }
}

/* Extra small mobile */
@media (max-width: 480px) {
    .chat-chart-container {
        padding: 12px;
        border-radius: 12px;
    }
    
    .chart-wrapper {
        height: 250px;
        min-height: 250px;
    }
    
    .chart-insights {
        display: none; /* Hide on very small screens to save space */
    }
    
    .chart-title {
        font-size: 14px;
    }
}
