/**
 * AI Insights Dashboard Module Styles
 * Per-user AI usage analytics with Chart.js charts.
 * Design system: Dark theme (#0F2A2A), green accent (#8BFF22)
 */

/* ========================================
   SECTION LAYOUT
======================================== */
.ai-insights-section {
    padding: 30px 40px;
    min-height: 100vh;
    background: linear-gradient(180deg, #0A1F1F 0%, #0F2A2A 40%, #0A1F1F 100%);
}

.ai-insights-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 28px;
}

.ai-insights-section .section-header h2 {
    margin: 0;
    font-size: 1.7rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-insights-section .section-header h2 .ai-insights-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: linear-gradient(135deg, rgba(139, 255, 34, 0.15), rgba(13, 79, 79, 0.4));
    color: #8BFF22;
    border: 1px solid rgba(139, 255, 34, 0.25);
}

.ai-insights-section .header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-insights-period-select {
    padding: 8px 14px;
    background: rgba(13, 79, 79, 0.6);
    color: #c0e8d0;
    border: 1px solid rgba(139, 255, 34, 0.2);
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.ai-insights-period-select:focus {
    outline: none;
    border-color: #8BFF22;
}

.ai-insights-section .btn-refresh {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(139, 255, 34, 0.1);
    color: #8BFF22;
    border: 1px solid rgba(139, 255, 34, 0.2);
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-insights-section .btn-refresh:hover {
    background: rgba(139, 255, 34, 0.2);
    border-color: rgba(139, 255, 34, 0.4);
}

/* ========================================
   SUBSCRIPTION BANNER
======================================== */
.ai-insights-subscription-banner {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 24px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, rgba(13, 79, 79, 0.5), rgba(139, 255, 34, 0.06));
    border: 1px solid rgba(139, 255, 34, 0.15);
    border-radius: 14px;
    flex-wrap: wrap;
}

.ai-insights-plan-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-insights-plan-badge.plan-none {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.ai-insights-plan-badge.plan-starter {
    background: rgba(96, 165, 250, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.3);
}

.ai-insights-plan-badge.plan-pro {
    background: rgba(139, 255, 34, 0.15);
    color: #8BFF22;
    border: 1px solid rgba(139, 255, 34, 0.3);
}

.ai-insights-plan-badge.plan-enterprise {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.ai-insights-quota-bars {
    display: flex;
    gap: 16px;
    flex: 1;
    flex-wrap: wrap;
}

.ai-insights-quota-item {
    flex: 1;
    min-width: 140px;
}

.ai-insights-quota-label {
    font-size: 0.75rem;
    color: rgba(192, 232, 208, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

.ai-insights-quota-label span {
    color: #c0e8d0;
    font-weight: 600;
}

.ai-insights-quota-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
}

.ai-insights-quota-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    background: linear-gradient(90deg, #8BFF22, #22c55e);
}

.ai-insights-quota-fill.quota-warning {
    background: linear-gradient(90deg, #eab308, #f59e0b);
}

.ai-insights-quota-fill.quota-danger {
    background: linear-gradient(90deg, #ef4444, #f87171);
}

.ai-insights-period-info {
    font-size: 0.78rem;
    color: rgba(192, 232, 208, 0.5);
    white-space: nowrap;
}

/* ========================================
   OVERVIEW STAT CARDS
======================================== */
.ai-insights-overview {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.ai-insights-stat {
    background: rgba(13, 79, 79, 0.35);
    border: 1px solid rgba(139, 255, 34, 0.1);
    border-radius: 14px;
    padding: 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.ai-insights-stat:hover {
    transform: translateY(-3px);
    border-color: rgba(139, 255, 34, 0.25);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.ai-insights-stat::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(139, 255, 34, 0.4), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-insights-stat:hover::before {
    opacity: 1;
}

.ai-insights-stat-icon {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

.ai-insights-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #8BFF22;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.ai-insights-stat-label {
    font-size: 0.78rem;
    color: rgba(192, 232, 208, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-insights-stat-sub {
    font-size: 0.72rem;
    color: rgba(192, 232, 208, 0.4);
    margin-top: 4px;
}

/* ========================================
   CARD CONTAINER
======================================== */
.ai-insights-card {
    background: rgba(13, 79, 79, 0.25);
    border: 1px solid rgba(139, 255, 34, 0.08);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.ai-insights-card:hover {
    border-color: rgba(139, 255, 34, 0.18);
}

.ai-insights-card h3 {
    margin: 0 0 16px 0;
    color: #e0f5e0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-insights-card h3 .card-subtitle {
    font-size: 0.75rem;
    color: rgba(192, 232, 208, 0.4);
    font-weight: 400;
    margin-left: auto;
}

/* ========================================
   GRID LAYOUTS
======================================== */
.ai-insights-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.ai-insights-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.ai-insights-full {
    width: 100%;
}

/* ========================================
   CHART CONTAINERS
======================================== */
.ai-insights-chart-wrap {
    position: relative;
    width: 100%;
    height: 280px;
}

.ai-insights-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.ai-insights-chart-wrap-sm {
    position: relative;
    width: 100%;
    height: 220px;
}

.ai-insights-chart-wrap-sm canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Doughnut chart centering */
.ai-insights-doughnut-wrap {
    position: relative;
    width: 100%;
    height: 260px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ai-insights-doughnut-wrap canvas {
    max-width: 260px;
    max-height: 260px;
}

.ai-insights-doughnut-center {
    position: absolute;
    text-align: center;
    pointer-events: none;
}

.ai-insights-doughnut-center .center-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #8BFF22;
    display: block;
}

.ai-insights-doughnut-center .center-label {
    font-size: 0.7rem;
    color: rgba(192, 232, 208, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========================================
   HEATMAP
======================================== */
.ai-insights-heatmap {
    display: grid;
    grid-template-columns: 50px repeat(24, 1fr);
    gap: 2px;
    font-size: 0.7rem;
}

.ai-insights-heatmap-header {
    color: rgba(192, 232, 208, 0.5);
    text-align: center;
    padding: 4px 0;
    font-weight: 600;
}

.ai-insights-heatmap-day {
    color: rgba(192, 232, 208, 0.6);
    text-align: right;
    padding: 4px 6px;
    font-weight: 500;
}

.ai-insights-heatmap-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    min-height: 18px;
    transition: transform 0.1s;
    cursor: default;
    position: relative;
}

.ai-insights-heatmap-cell:hover {
    transform: scale(1.3);
    z-index: 2;
}

.ai-insights-heatmap-cell[data-count="0"],
.ai-insights-heatmap-cell:not([data-count]) {
    background: rgba(255, 255, 255, 0.03);
}

.ai-insights-heatmap-cell.heat-1 {
    background: rgba(139, 255, 34, 0.15);
}

.ai-insights-heatmap-cell.heat-2 {
    background: rgba(139, 255, 34, 0.3);
}

.ai-insights-heatmap-cell.heat-3 {
    background: rgba(139, 255, 34, 0.5);
}

.ai-insights-heatmap-cell.heat-4 {
    background: rgba(139, 255, 34, 0.7);
}

.ai-insights-heatmap-cell.heat-5 {
    background: #8BFF22;
}

.ai-insights-heatmap-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 10px;
    font-size: 0.72rem;
    color: rgba(192, 232, 208, 0.45);
}

.ai-insights-heatmap-legend-cell {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* ========================================
   TABLE STYLES
======================================== */
.ai-insights-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.ai-insights-table thead th {
    text-align: left;
    padding: 10px 12px;
    color: rgba(192, 232, 208, 0.7);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(139, 255, 34, 0.12);
}

.ai-insights-table tbody td {
    padding: 10px 12px;
    color: #c0e8d0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    vertical-align: middle;
}

.ai-insights-table tbody tr {
    transition: background 0.15s;
}

.ai-insights-table tbody tr:hover {
    background: rgba(139, 255, 34, 0.04);
}

.ai-insights-table code {
    background: rgba(139, 255, 34, 0.1);
    color: #8BFF22;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.82rem;
}

.ai-insights-table .empty-state {
    text-align: center;
    color: rgba(192, 232, 208, 0.4);
    padding: 24px !important;
    font-style: italic;
}

/* ========================================
   BADGES
======================================== */
.ai-insights-action-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(139, 255, 34, 0.1);
    color: #8BFF22;
    text-transform: capitalize;
    white-space: nowrap;
}

.ai-insights-action-badge.action-suggest { color: #22c55e; background: rgba(34, 197, 94, 0.12); }
.ai-insights-action-badge.action-chat { color: #60a5fa; background: rgba(96, 165, 250, 0.12); }
.ai-insights-action-badge.action-generate { color: #a855f7; background: rgba(168, 85, 247, 0.12); }
.ai-insights-action-badge.action-seo { color: #f59e0b; background: rgba(245, 158, 11, 0.12); }
.ai-insights-action-badge.action-pricing { color: #14b8a6; background: rgba(20, 184, 166, 0.12); }
.ai-insights-action-badge.action-trendy { color: #ec4899; background: rgba(236, 72, 153, 0.12); }

.ai-insights-success-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.ai-insights-success-dot.success { background: #22c55e; }
.ai-insights-success-dot.failure { background: #ef4444; }

/* ========================================
   STREAK CARDS
======================================== */
.ai-insights-streaks {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.ai-insights-streak-card {
    flex: 1;
    min-width: 120px;
    padding: 14px;
    background: rgba(139, 255, 34, 0.05);
    border: 1px solid rgba(139, 255, 34, 0.1);
    border-radius: 10px;
    text-align: center;
    transition: border-color 0.2s;
}

.ai-insights-streak-card:hover {
    border-color: rgba(139, 255, 34, 0.25);
}

.ai-insights-streak-card:first-child {
    border-color: rgba(139, 255, 34, 0.3);
    background: rgba(139, 255, 34, 0.08);
}

.ai-insights-streak-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #8BFF22;
}

.ai-insights-streak-label {
    font-size: 0.72rem;
    color: rgba(192, 232, 208, 0.5);
    margin-top: 2px;
}

.ai-insights-streak-dates {
    font-size: 0.68rem;
    color: rgba(192, 232, 208, 0.35);
    margin-top: 4px;
}

/* ========================================
   FIELD USAGE BAR
======================================== */
.ai-insights-field-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-insights-field-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-insights-field-name {
    width: 100px;
    font-size: 0.82rem;
    color: #c0e8d0;
    text-align: right;
    flex-shrink: 0;
    text-transform: capitalize;
}

.ai-insights-field-track {
    flex: 1;
    height: 24px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.ai-insights-field-fill {
    height: 100%;
    background: linear-gradient(90deg, #8BFF22, rgba(139, 255, 34, 0.4));
    border-radius: 6px;
    transition: width 0.6s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
}

.ai-insights-field-fill span {
    font-size: 0.72rem;
    color: #0F2A2A;
    font-weight: 700;
    white-space: nowrap;
}

.ai-insights-field-count {
    width: 50px;
    font-size: 0.82rem;
    color: rgba(192, 232, 208, 0.6);
    text-align: left;
    flex-shrink: 0;
}

/* ========================================
   RECENT ACTIVITY TIMELINE
======================================== */
.ai-insights-timeline {
    max-height: 440px;
    overflow-y: auto;
    padding-right: 4px;
}

.ai-insights-timeline::-webkit-scrollbar {
    width: 4px;
}

.ai-insights-timeline::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 2px;
}

.ai-insights-timeline::-webkit-scrollbar-thumb {
    background: rgba(139, 255, 34, 0.2);
    border-radius: 2px;
}

.ai-insights-timeline-item {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.15s;
}

.ai-insights-timeline-item:hover {
    background: rgba(139, 255, 34, 0.03);
    margin: 0 -8px;
    padding-left: 8px;
    padding-right: 8px;
    border-radius: 8px;
}

.ai-insights-timeline-item:last-child {
    border-bottom: none;
}

.ai-insights-timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
    background: #8BFF22;
}

.ai-insights-timeline-dot.dot-error {
    background: #ef4444;
}

.ai-insights-timeline-content {
    flex: 1;
    min-width: 0;
}

.ai-insights-timeline-action {
    font-size: 0.88rem;
    color: #e0f5e0;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-insights-timeline-meta {
    font-size: 0.75rem;
    color: rgba(192, 232, 208, 0.4);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.ai-insights-timeline-time {
    font-size: 0.75rem;
    color: rgba(192, 232, 208, 0.35);
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 5px;
}

/* ========================================
   LOADING / EMPTY STATES
======================================== */
.ai-insights-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

.ai-insights-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(139, 255, 34, 0.1);
    border-top-color: #8BFF22;
    border-radius: 50%;
    animation: ai-insights-spin 0.8s linear infinite;
}

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

.ai-insights-loading-text {
    color: rgba(192, 232, 208, 0.5);
    font-size: 0.9rem;
}

.ai-insights-empty {
    text-align: center;
    padding: 40px 20px;
    color: rgba(192, 232, 208, 0.4);
}

.ai-insights-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.ai-insights-empty-text {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.ai-insights-empty-sub {
    font-size: 0.8rem;
    color: rgba(192, 232, 208, 0.3);
}

/* ========================================
   RESPONSIVE
======================================== */
@media (max-width: 1200px) {
    .ai-insights-overview {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .ai-insights-heatmap {
        overflow-x: auto;
        min-width: 600px;
    }
}

@media (max-width: 768px) {
    .ai-insights-section {
        padding: 16px;
    }

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

    .ai-insights-grid-2,
    .ai-insights-grid-3 {
        grid-template-columns: 1fr;
    }

    .ai-insights-subscription-banner {
        flex-direction: column;
        align-items: stretch;
    }

    .ai-insights-quota-bars {
        flex-direction: column;
    }

    .ai-insights-heatmap {
        display: none;
    }

    .ai-insights-field-name {
        width: 70px;
        font-size: 0.75rem;
    }
}

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

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

    .ai-insights-streaks {
        flex-direction: column;
    }
}
