/**
 * Comprehensive Analytics Dashboard Styles
 * Modern, responsive design with Chart.js integration
 */

/* CSS Custom Properties for theming */
:root {
    --analytics-primary: #007cba;
    --analytics-secondary: #005a87;
    --analytics-success: #28a745;
    --analytics-warning: #ffc107;
    --analytics-danger: #dc3545;
    --analytics-info: #17a2b8;
    --analytics-light: #f8f9fa;
    --analytics-dark: #333333;
    --analytics-muted: #6c757d;
    
    --analytics-border: #e9ecef;
    --analytics-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --analytics-shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);
    --analytics-radius: 12px;
    --analytics-radius-sm: 6px;
    
    --analytics-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --analytics-font-size: 14px;
    --analytics-line-height: 1.5;
    
    --analytics-grid-gap: 24px;
    --analytics-container-padding: 32px;
    
    /* Animation variables */
    --analytics-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --analytics-animation-duration: 0.3s;
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    :root {
        --analytics-light: #2d3748;
        --analytics-dark: #ffffff;
        --analytics-muted: #a0aec0;
        --analytics-border: #4a5568;
    }
}

/* Base Dashboard Styles */
.convertybot-comprehensive-analytics {
    font-family: var(--analytics-font-family);
    font-size: var(--analytics-font-size);
    line-height: var(--analytics-line-height);
    color: var(--analytics-dark);
    max-width: none;
    margin: 0;
    padding: 0;
    background: #f0f2f5;
    min-height: 100vh;
}

.convertybot-comprehensive-analytics * {
    box-sizing: border-box;
}

/* Dashboard Header */
.analytics-header {
    background: white;
    padding: var(--analytics-container-padding);
    border-bottom: 2px solid var(--analytics-border);
    position: sticky;
    top: 32px; /* WordPress admin bar height */
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    box-shadow: var(--analytics-shadow);
}

.header-main {
    flex: 1;
    min-width: 300px;
}

.dashboard-title {
    margin: 0 0 8px 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--analytics-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}

.dashboard-title .dashicons {
    font-size: 32px;
    color: var(--analytics-primary);
}

.header-subtitle {
    color: var(--analytics-muted);
    font-size: 16px;
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.date-range-selector,
.comparison-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range-selector label,
.comparison-selector label {
    font-weight: 600;
    color: var(--analytics-dark);
    white-space: nowrap;
}

.date-range-selector select,
.comparison-selector select {
    padding: 8px 12px;
    border: 2px solid var(--analytics-border);
    border-radius: var(--analytics-radius-sm);
    background: white;
    font-size: 14px;
    min-width: 140px;
    transition: var(--analytics-transition);
}

.date-range-selector select:focus,
.comparison-selector select:focus {
    outline: none;
    border-color: var(--analytics-primary);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.header-actions .button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--analytics-radius-sm);
    font-weight: 600;
    transition: var(--analytics-transition);
    border: 2px solid transparent;
    text-decoration: none;
}

.header-actions .button:hover {
    transform: translateY(-2px);
    box-shadow: var(--analytics-shadow-hover);
}

.header-actions .button.button-secondary {
    background: var(--analytics-light);
    border-color: var(--analytics-border);
    color: var(--analytics-dark);
}

.header-actions .button.button-secondary:hover {
    background: #e2e6ea;
    border-color: var(--analytics-primary);
}

.real-time-toggle {
    position: relative;
}

.real-time-toggle[data-enabled="true"] {
    background: var(--analytics-success) !important;
    border-color: var(--analytics-success) !important;
    color: white !important;
}

.real-time-toggle[data-enabled="false"] {
    background: var(--analytics-muted) !important;
    border-color: var(--analytics-muted) !important;
    color: white !important;
}

/* Real-time Status Bar */
.real-time-status-bar {
    background: linear-gradient(135deg, var(--analytics-success), #20c997);
    color: white;
    padding: 12px var(--analytics-container-padding);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

.status-dot.active {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.last-update {
    font-size: 12px;
    opacity: 0.9;
}

/* Executive Summary Section */
.executive-summary {
    padding: var(--analytics-container-padding);
    background: white;
    margin-bottom: var(--analytics-grid-gap);
}

.section-title {
    margin: 0 0 24px 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--analytics-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-title .dashicons {
    font-size: 24px;
    color: var(--analytics-primary);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--analytics-grid-gap);
}

/* Metric Cards */
.metric-card {
    background: white;
    border-radius: var(--analytics-radius);
    padding: 24px;
    box-shadow: var(--analytics-shadow);
    transition: var(--analytics-transition);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--analytics-shadow-hover);
    border-color: var(--analytics-primary);
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.metric-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--analytics-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    flex-shrink: 0;
}

.metric-icon.revenue {
    background: linear-gradient(135deg, var(--analytics-success), #20c997);
}

.metric-icon.conversations {
    background: linear-gradient(135deg, var(--analytics-primary), var(--analytics-secondary));
}

.metric-icon.conversion {
    background: linear-gradient(135deg, var(--analytics-warning), #e0a800);
}

.metric-icon.satisfaction {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
}

.metric-icon.ai-performance {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.metric-icon.engagement {
    background: linear-gradient(135deg, #f093fb, #f5576c);
}

.metric-info {
    flex: 1;
}

.metric-value {
    font-size: 32px;
    font-weight: 800;
    line-height: 1;
    margin: 0 0 4px 0;
    color: var(--analytics-dark);
}

.metric-label {
    font-size: 14px;
    color: var(--analytics-muted);
    margin: 0 0 8px 0;
    font-weight: 600;
}

.metric-change {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

.change-indicator {
    font-size: 16px;
    font-weight: bold;
}

.change-indicator.positive {
    color: var(--analytics-success);
}

.change-indicator.negative {
    color: var(--analytics-danger);
}

.change-indicator.neutral {
    color: var(--analytics-muted);
}

.change-value {
    color: inherit;
}

.card-chart {
    height: 60px;
    margin-top: 12px;
    opacity: 0.8;
}

.card-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Dashboard Tabs */
.dashboard-tabs {
    background: white;
    border-radius: var(--analytics-radius);
    box-shadow: var(--analytics-shadow);
    overflow: hidden;
    margin-bottom: var(--analytics-grid-gap);
}

.tab-navigation {
    display: flex;
    background: var(--analytics-light);
    border-bottom: 2px solid var(--analytics-border);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tab-navigation::-webkit-scrollbar {
    display: none;
}

.tab-button {
    background: none;
    border: none;
    padding: 16px 24px;
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-muted);
    cursor: pointer;
    transition: var(--analytics-transition);
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    position: relative;
}

.tab-button:hover {
    background: rgba(0, 124, 186, 0.08);
    color: var(--analytics-primary);
}

.tab-button.active {
    color: var(--analytics-primary);
    background: white;
    border-bottom-color: var(--analytics-primary);
}

.tab-content {
    display: none;
    padding: var(--analytics-container-padding);
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--analytics-grid-gap);
    align-items: start;
}

/* Dashboard Widgets */
.dashboard-widget {
    background: white;
    border-radius: var(--analytics-radius);
    box-shadow: var(--analytics-shadow);
    overflow: hidden;
    transition: var(--analytics-transition);
    border: 1px solid var(--analytics-border);
}

.dashboard-widget:hover {
    box-shadow: var(--analytics-shadow-hover);
}

.widget-header {
    padding: 20px 24px;
    border-bottom: 2px solid var(--analytics-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--analytics-light);
}

.widget-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.widget-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.widget-controls select {
    padding: 6px 10px;
    border: 1px solid var(--analytics-border);
    border-radius: var(--analytics-radius-sm);
    font-size: 13px;
    background: white;
}

.widget-controls button {
    padding: 8px 12px;
    border: 1px solid var(--analytics-border);
    border-radius: var(--analytics-radius-sm);
    background: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--analytics-transition);
}

.widget-controls button:hover {
    background: var(--analytics-primary);
    color: white;
    border-color: var(--analytics-primary);
}

.widget-content {
    padding: 24px;
}

.widget-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--analytics-success);
}

/* Conversion Funnel Widget */
.funnel-visualization {
    margin-bottom: 24px;
    height: 300px;
}

.funnel-metrics {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 20px;
}

.funnel-step-metrics {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.funnel-step-metric {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--analytics-border);
}

.funnel-step-metric:last-child {
    border-bottom: none;
}

.step-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.step-label {
    font-weight: 600;
    color: var(--analytics-dark);
}

.step-count {
    font-size: 12px;
    color: var(--analytics-muted);
}

.step-bar {
    width: 100px;
    height: 8px;
    background: var(--analytics-border);
    border-radius: 4px;
    overflow: hidden;
}

.step-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--analytics-primary), var(--analytics-secondary));
    border-radius: 4px;
    transition: width 0.8s ease-out;
}

.step-percentage {
    font-weight: 700;
    color: var(--analytics-primary);
    text-align: right;
    min-width: 40px;
}

/* Real-time Widget */
.real-time-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.real-time-metric {
    text-align: center;
    padding: 16px;
    background: linear-gradient(135deg, var(--analytics-light), #f1f3f5);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.real-time-metric:hover {
    transform: scale(1.02);
    box-shadow: var(--analytics-shadow);
}

.real-time-metric .metric-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.real-time-metric .metric-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--analytics-primary);
    display: block;
}

.activity-feed {
    border-top: 2px solid var(--analytics-border);
    padding-top: 20px;
}

.feed-header h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.activity-list {
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--analytics-border) transparent;
}

.activity-list::-webkit-scrollbar {
    width: 6px;
}

.activity-list::-webkit-scrollbar-track {
    background: transparent;
}

.activity-list::-webkit-scrollbar-thumb {
    background: var(--analytics-border);
    border-radius: 3px;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--analytics-border);
    animation: slideInRight 0.3s ease-out;
}

.activity-item:last-child {
    border-bottom: none;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}

.activity-icon.chat {
    background: var(--analytics-primary);
}

.activity-icon.purchase {
    background: var(--analytics-success);
}

.activity-icon.view {
    background: var(--analytics-info);
}

.activity-content {
    flex: 1;
    font-size: 13px;
}

.activity-title {
    font-weight: 600;
    color: var(--analytics-dark);
    margin: 0 0 2px 0;
}

.activity-meta {
    color: var(--analytics-muted);
    font-size: 12px;
}

.activity-time {
    font-size: 12px;
    color: var(--analytics-muted);
    white-space: nowrap;
}

/* Performance Trends Widget */
.trend-chart-container {
    height: 200px;
    margin-bottom: 20px;
}

.trend-insights {
    padding-top: 20px;
    border-top: 2px solid var(--analytics-border);
}

.insight-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    border-left: 4px solid var(--analytics-success);
}

.insight-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--analytics-success);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.insight-content h5 {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.insight-content p {
    margin: 0;
    font-size: 13px;
    color: var(--analytics-muted);
}

/* Top Products Widget */
.products-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.product-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.product-item:hover {
    background: #e8f4f8;
    transform: translateX(4px);
}

.product-rank {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--analytics-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.product-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.product-image {
    width: 48px;
    height: 48px;
    border-radius: var(--analytics-radius-sm);
    object-fit: cover;
    border: 2px solid var(--analytics-border);
}

.product-details {
    flex: 1;
}

.product-name {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.product-metrics {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--analytics-muted);
}

.product-revenue {
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-success);
}

/* AI Performance Widgets */
.conversation-quality-widget .widget-content {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 24px;
    align-items: center;
}

.quality-score {
    text-align: center;
}

.score-circle {
    width: 120px;
    height: 120px;
    margin: 0 auto 8px;
}

.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 100%;
}

.circle-bg {
    fill: none;
    stroke: var(--analytics-border);
    stroke-width: 2.5;
}

.circle {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    animation: progress 1s ease-out forwards;
    stroke: var(--analytics-primary);
}

.percentage {
    fill: var(--analytics-primary);
    font-family: var(--analytics-font-family);
    font-size: 6px;
    font-weight: 700;
    text-anchor: middle;
}

@keyframes progress {
    0% {
        stroke-dasharray: 0 100;
    }
}

.score-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quality-breakdown {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.quality-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 12px;
    align-items: center;
}

.quality-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-dark);
}

.quality-bar {
    width: 100px;
    height: 8px;
    background: var(--analytics-border);
    border-radius: 4px;
    overflow: hidden;
}

.quality-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--analytics-primary), var(--analytics-secondary));
    border-radius: 4px;
    animation: progressBar 1s ease-out;
}

@keyframes progressBar {
    from { width: 0; }
}

.quality-value {
    font-weight: 700;
    color: var(--analytics-primary);
    text-align: right;
    min-width: 48px;
}

/* AI Learning Widget */
.learning-chart {
    height: 200px;
    margin-bottom: 20px;
}

.learning-insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    padding-top: 20px;
    border-top: 2px solid var(--analytics-border);
}

.insight {
    text-align: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.insight-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insight-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--analytics-primary);
}

/* Conversation Categories Widget */
.categories-chart {
    height: 300px;
    margin-bottom: 20px;
}

.categories-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--analytics-border);
}

.legend-item:last-child {
    border-bottom: none;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label {
    flex: 1;
    margin-left: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-dark);
}

.legend-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-primary);
}

/* Revenue Attribution Widget */
.attribution-chart {
    height: 200px;
    margin-bottom: 20px;
}

.attribution-breakdown {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.attribution-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 12px 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.attribution-source {
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-dark);
}

.attribution-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-success);
}

.attribution-percentage {
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-primary);
    text-align: right;
}

/* Sales Velocity Widget */
.velocity-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.velocity-metric {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.velocity-metric:hover {
    background: #e8f4f8;
    transform: translateY(-2px);
}

.velocity-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--analytics-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.velocity-info {
    flex: 1;
}

.velocity-value {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: var(--analytics-primary);
    line-height: 1;
}

.velocity-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 2px 0;
}

.velocity-description {
    display: block;
    font-size: 12px;
    color: var(--analytics-muted);
}

.velocity-trend {
    height: 150px;
}

/* Coupon Performance Widget */
.coupon-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.coupon-stat {
    text-align: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.coupon-stat .stat-value {
    display: block;
    font-size: 20px;
    font-weight: 800;
    color: var(--analytics-primary);
    margin-bottom: 4px;
}

.coupon-stat .stat-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.coupon-chart {
    height: 200px;
}

/* Customer Segmentation Widget */
.segmentation-chart {
    height: 200px;
    margin-bottom: 20px;
}

.segments-breakdown {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.segment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.segment-item:hover {
    background: #e8f4f8;
    transform: translateX(4px);
}

.segment-info {
    flex: 1;
}

.segment-name {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-dark);
    margin-bottom: 2px;
}

.segment-count {
    font-size: 12px;
    color: var(--analytics-muted);
}

.segment-value {
    text-align: right;
}

.segment-revenue {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-success);
    margin-bottom: 2px;
}

.segment-percentage {
    font-size: 12px;
    color: var(--analytics-muted);
}

/* Customer Lifetime Value Widget */
.clv-metrics {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 24px;
    align-items: center;
    margin-bottom: 24px;
}

.clv-primary {
    text-align: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--analytics-success), #20c997);
    color: white;
    border-radius: var(--analytics-radius);
}

.clv-value {
    display: block;
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 8px;
}

.clv-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.clv-secondary {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.clv-secondary-metric {
    text-align: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.clv-secondary-metric .metric-value {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: var(--analytics-primary);
    margin-bottom: 4px;
}

.clv-secondary-metric .metric-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.clv-chart {
    height: 200px;
}

/* Cohort Analysis Widget */
.cohort-heatmap {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 20px;
    margin-bottom: 20px;
    text-align: center;
    color: var(--analytics-muted);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cohort-insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
}

.cohort-insight {
    text-align: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.cohort-insight .insight-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cohort-insight .insight-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--analytics-primary);
}

/* Product Performance Matrix Widget */
.matrix-chart {
    height: 400px;
    margin-bottom: 20px;
}

.matrix-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.legend-axis {
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-axis.vertical {
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

/* AI Recommendations Widget */
.recommendations-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.recommendation-item {
    display: flex;
    gap: 16px;
    padding: 20px;
    border-radius: var(--analytics-radius);
    border-left: 4px solid;
}

.recommendation-item.high-priority {
    background: #fff8e1;
    border-left-color: var(--analytics-warning);
}

.recommendation-item.medium-priority {
    background: #e8f5e8;
    border-left-color: var(--analytics-success);
}

.recommendation-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.high-priority .recommendation-icon {
    background: var(--analytics-warning);
}

.medium-priority .recommendation-icon {
    background: var(--analytics-success);
}

.recommendation-content {
    flex: 1;
}

.recommendation-content h5 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.recommendation-content p {
    margin: 0 0 12px 0;
    color: var(--analytics-muted);
    line-height: 1.5;
}

.recommendation-impact {
    display: flex;
    gap: 8px;
    align-items: center;
}

.impact-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    text-transform: uppercase;
}

.impact-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-success);
}

/* Category Performance Widget */
.category-chart {
    height: 200px;
    margin-bottom: 20px;
}

.category-metrics {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.category-metric {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--analytics-border);
}

.category-metric:last-child {
    border-bottom: none;
}

.category-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-dark);
}

.category-bar {
    width: 100px;
    height: 8px;
    background: var(--analytics-border);
    border-radius: 4px;
    overflow: hidden;
}

.category-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--analytics-primary), var(--analytics-secondary));
    border-radius: 4px;
    transition: width 0.8s ease-out;
}

.category-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-success);
    text-align: right;
}

/* Engagement Widgets */
.engagement-heatmap-widget .widget-content {
    text-align: center;
}

.heatmap-container {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 40px;
    margin-bottom: 20px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    color: var(--analytics-muted);
}

.heatmap-placeholder .dashicons {
    font-size: 48px;
    opacity: 0.5;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
}

.heat-scale {
    display: flex;
    gap: 2px;
}

.heat-color {
    width: 20px;
    height: 20px;
    border-radius: 2px;
}

/* Session Journey Widget */
.journey-flow {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 40px;
    margin-bottom: 20px;
    text-align: center;
    color: var(--analytics-muted);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.journey-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
}

.journey-metric {
    text-align: center;
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
}

.journey-metric .metric-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.journey-metric .metric-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--analytics-primary);
}

/* Behavioral Patterns Widget */
.patterns-chart {
    height: 200px;
    margin-bottom: 20px;
}

.patterns-insights {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pattern-insight {
    padding: 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    border-left: 4px solid var(--analytics-primary);
}

.insight-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

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

.insight-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.pattern-insight p {
    margin: 0;
    color: var(--analytics-muted);
    line-height: 1.5;
}

/* A/B Testing Widget */
.ab-tests-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ab-test-item {
    border: 2px solid var(--analytics-border);
    border-radius: var(--analytics-radius);
    padding: 20px;
    background: white;
}

.ab-test-item.active {
    border-color: var(--analytics-primary);
    background: #f8fbff;
}

.test-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.test-name {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.test-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.test-status.running {
    background: var(--analytics-success);
    color: white;
}

.test-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.test-progress .progress-bar {
    flex: 1;
    height: 8px;
    background: var(--analytics-border);
    border-radius: 4px;
    overflow: hidden;
}

.test-progress .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--analytics-primary), var(--analytics-secondary));
    transition: width 0.8s ease-out;
}

.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--analytics-muted);
    white-space: nowrap;
}

.test-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.variant {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius-sm);
    position: relative;
}

.variant.winner {
    background: #e8f5e8;
    border: 2px solid var(--analytics-success);
}

.variant-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--analytics-dark);
}

.variant-conversion {
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-primary);
}

.winner-badge {
    position: absolute;
    right: -8px;
    top: -8px;
    background: var(--analytics-success);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.test-significance {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.significance-label {
    color: var(--analytics-muted);
    font-weight: 600;
}

.significance-value {
    color: var(--analytics-success);
    font-weight: 700;
}

/* Predictive Analytics Widget */
.prediction-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.prediction-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.prediction-card:hover {
    background: #e8f4f8;
    transform: translateY(-2px);
}

.prediction-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--analytics-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.prediction-content {
    flex: 1;
}

.prediction-content h5 {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.prediction-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--analytics-primary);
    margin-bottom: 2px;
}

.prediction-period {
    font-size: 12px;
    color: var(--analytics-muted);
    margin-bottom: 4px;
}

.prediction-confidence {
    font-size: 11px;
    color: var(--analytics-success);
    font-weight: 600;
}

.forecast-chart {
    height: 200px;
}

/* Custom Metrics Widget */
.custom-metrics-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.custom-metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    transition: var(--analytics-transition);
}

.custom-metric-item:hover {
    background: #e8f4f8;
    transform: translateX(4px);
}

.metric-definition {
    flex: 1;
}

.metric-definition h5 {
    margin: 0 0 4px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.metric-definition p {
    margin: 0;
    font-size: 12px;
    color: var(--analytics-muted);
    font-family: monospace;
    background: rgba(0, 124, 186, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
}

.metric-current-value {
    text-align: right;
}

.metric-current-value .value {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: var(--analytics-primary);
    margin-bottom: 2px;
}

.metric-current-value .trend {
    font-size: 12px;
    font-weight: 700;
}

.trend.positive {
    color: var(--analytics-success);
}

.trend.negative {
    color: var(--analytics-danger);
}

/* Modal Styles */
.analytics-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: var(--analytics-radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.modal-header {
    padding: 24px;
    border-bottom: 2px solid var(--analytics-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--analytics-light);
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.modal-close {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--analytics-transition);
    color: var(--analytics-muted);
}

.modal-close:hover {
    background: var(--analytics-border);
    color: var(--analytics-dark);
}

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 24px;
    border-top: 2px solid var(--analytics-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: var(--analytics-light);
}

/* Export Options */
.export-options {
    display: grid;
    gap: 24px;
}

.export-format,
.export-sections,
.export-range {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.export-format h4,
.export-sections h4,
.export-range h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.export-format label,
.export-sections label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    cursor: pointer;
    transition: var(--analytics-transition);
}

.export-format label:hover,
.export-sections label:hover {
    color: var(--analytics-primary);
}

.export-range select {
    padding: 8px 12px;
    border: 2px solid var(--analytics-border);
    border-radius: var(--analytics-radius-sm);
    font-size: 14px;
    background: white;
}

/* Dashboard Customization */
.dashboard-customization {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.widget-library h4,
.dashboard-preview h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--analytics-dark);
}

.widget-list {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 16px;
    min-height: 300px;
}

.layout-preview {
    background: var(--analytics-light);
    border-radius: var(--analytics-radius);
    padding: 16px;
    min-height: 300px;
}

/* Responsive Design */
@media (max-width: 1400px) {
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }
}

@media (max-width: 1200px) {
    :root {
        --analytics-container-padding: 24px;
        --analytics-grid-gap: 20px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .summary-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
    
    .analytics-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    
    .header-controls {
        justify-content: space-between;
    }
}

@media (max-width: 768px) {
    :root {
        --analytics-container-padding: 16px;
        --analytics-grid-gap: 16px;
    }
    
    .summary-grid {
        grid-template-columns: 1fr;
    }
    
    .tab-navigation {
        flex-direction: column;
    }
    
    .tab-button {
        text-align: left;
        border-bottom: none;
        border-left: 3px solid transparent;
    }
    
    .tab-button.active {
        border-left-color: var(--analytics-primary);
        border-bottom: none;
    }
    
    .metric-card .card-header {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    
    .header-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .dashboard-customization {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
    }
    
    .conversation-quality-widget .widget-content {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .clv-metrics {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .attribution-item,
    .funnel-step-metric,
    .segment-item {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 8px;
    }
    
    .product-item {
        flex-direction: column;
        text-align: center;
    }
    
    .custom-metric-item {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    
    .prediction-cards {
        grid-template-columns: 1fr;
    }
    
    .prediction-card {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .analytics-header {
        padding: 16px;
        position: relative;
        top: 0;
    }
    
    .dashboard-title {
        font-size: 24px;
    }
    
    .header-subtitle {
        font-size: 14px;
    }
    
    .tab-content {
        padding: 16px;
    }
    
    .widget-header {
        padding: 16px;
    }
    
    .widget-content {
        padding: 16px;
    }
    
    .metric-value {
        font-size: 28px;
    }
    
    .velocity-metrics,
    .coupon-stats,
    .real-time-stats,
    .learning-insights,
    .journey-metrics,
    .cohort-insights {
        grid-template-columns: 1fr;
    }
    
    .heatmap-legend {
        flex-direction: column;
        text-align: center;
    }
}

/* Print Styles */
@media print {
    .analytics-header,
    .header-actions,
    .tab-navigation,
    .widget-controls,
    .analytics-modal {
        display: none !important;
    }
    
    .tab-content {
        display: block !important;
    }
    
    .dashboard-widget {
        break-inside: avoid;
        margin-bottom: 20px;
    }
    
    .convertybot-comprehensive-analytics {
        background: white !important;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --analytics-border: #000000;
        --analytics-muted: #000000;
    }
    
    .metric-card,
    .dashboard-widget {
        border: 2px solid #000000;
    }
}

/* Focus indicators for accessibility */
.tab-button:focus,
.button:focus,
select:focus,
input:focus {
    outline: 2px solid var(--analytics-primary);
    outline-offset: 2px;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}