/**
 * Modern Dashboard Styles
 * Inspired by Flowbite design system
 * Professional enterprise-grade dashboard design
 */

:root {
    /* Modern Color Palette */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;
    
    /* Gray Scale */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Success/Error/Warning */
    --success-50: #f0fdf4;
    --success-500: #22c55e;
    --success-600: #16a34a;
    --success-700: #15803d;
    
    --error-50: #fef2f2;
    --error-500: #ef4444;
    --error-600: #dc2626;
    --error-700: #b91c1c;
    
    --warning-50: #fffbeb;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --warning-700: #b45309;
    
    /* Layout */
    --sidebar-width: 256px;
    --sidebar-collapsed: 64px;
    --header-height: 72px;
    --border-radius: 0.5rem;
    --border-radius-lg: 0.75rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --gray-50: #1f2937;
    --gray-100: #374151;
    --gray-200: #4b5563;
    --gray-300: #6b7280;
    --gray-400: #9ca3af;
    --gray-500: #d1d5db;
    --gray-600: #e5e7eb;
    --gray-700: #f3f4f6;
    --gray-800: #f9fafb;
    --gray-900: #ffffff;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* GLOBAL CHART FIX - Prevent ALL charts from infinite growth */
canvas {
    display: block !important;
    box-sizing: border-box !important;
}

/* Force max dimensions on any chart canvas */
.srm-dashboard-v2 canvas,
.srm-project-selector canvas {
    max-width: 100% !important;
    max-height: 500px !important;
}

/* Override any conflicting styles */
body.srm-modern-dashboard {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
    background: var(--gray-50) !important;
}

.srm-dashboard-v2 *,
.srm-project-selector * {
    font-family: inherit !important;
}

/* Force modern styles on key elements */
body.srm-modern-dashboard .dashboard-container {
    background: #f9fafb !important;
}

body.srm-modern-dashboard .card,
body.srm-modern-dashboard .metric-card,
body.srm-modern-dashboard .project-card {
    background: white !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1) !important;
    border: 1px solid #e5e7eb !important;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Modern Dashboard Container */
.srm-dashboard-v2,
.srm-project-selector {
    min-height: 100vh;
    background: var(--gray-50) !important;
    width: 100%;
    margin: 0 !important;
    padding: 0 !important;
}

.dashboard-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--gray-50);
}

/* Modern Sidebar */
.dashboard-sidebar {
    width: var(--sidebar-width) !important;
    background: white !important;
    border-right: 1px solid var(--gray-200) !important;
    display: flex !important;
    flex-direction: column !important;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow) !important;
    z-index: 40;
}

.dashboard-sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
}

.logo-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon svg {
    width: 32px;
    height: 32px;
    color: var(--primary-600);
}

.logo-text {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--gray-900);
    transition: opacity 0.3s;
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    background: var(--gray-100);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--gray-200);
}

.sidebar-toggle:hover {
    background: var(--gray-200);
    transform: translateY(-1px);
}

/* Modern Navigation */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--border-radius);
    color: var(--gray-600);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--gray-900);
    transform: translateX(2px);
}

.nav-item.active {
    background: var(--primary-50);
    color: var(--primary-700);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--primary-600);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--error-500);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    min-width: 20px;
    text-align: center;
}

/* Modern Header */
.dashboard-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.project-type-badge {
    background: var(--primary-100);
    color: var(--primary-700);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Modern Search */
.global-search {
    position: relative;
    width: 400px;
}

.search-input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    background: var(--gray-50);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: white;
}

.search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--gray-400);
}

/* Modern Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-600) !important;
    color: white !important;
    box-shadow: var(--shadow) !important;
}

.btn-primary:hover {
    background: var(--primary-700);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
}

.btn-icon:hover {
    background: var(--gray-50);
    color: var(--gray-900);
    transform: translateY(-1px);
}

/* Modern Cards */
.card {
    background: white;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
}

.card-body {
    padding: 1.5rem;
}

/* Modern Metric Cards */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: white !important;
    border-radius: var(--border-radius-lg) !important;
    padding: 1.5rem !important;
    border: 1px solid var(--gray-200) !important;
    box-shadow: var(--shadow) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

.metric-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    background: var(--primary-50);
    color: var(--primary-600);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
}

.metric-change {
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
}

.metric-change.positive {
    color: var(--success-700);
    background: var(--success-50);
}

.metric-change.negative {
    color: var(--error-700);
    background: var(--error-50);
}

/* Modern Charts */
.chart-container {
    background: white;
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}

.chart-header {
    margin-bottom: 1.5rem;
}

.chart-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.chart-subtitle {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.chart-wrapper {
    position: relative;
    height: 320px;
    width: 100%;
    max-height: 320px;
    overflow: hidden;
}

/* CRITICAL: Prevent Chart.js infinite growth bug */
.chart-container canvas,
.chart-wrapper canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    height: 100% !important;
    width: 100% !important;
    max-height: 100% !important;
    max-width: 100% !important;
}

/* Fix all specific chart IDs */
#sentiment-timeline-chart,
#sentiment-donut-chart,
#geographic-chart,
#competitor-chart,
#narrative-heat-chart,
canvas[id^="chart-"] {
    display: block !important;
    box-sizing: border-box !important;
    height: inherit !important;
    width: inherit !important;
}

/* Container-specific heights */
.sentiment-timeline-container {
    height: 400px !important;
    max-height: 400px !important;
    position: relative !important;
}

.sentiment-donut-container {
    height: 200px !important;
    max-height: 200px !important;
    position: relative !important;
}

/* Project card mini charts */
.project-chart {
    height: 100px !important;
    max-height: 100px !important;
    position: relative !important;
    overflow: hidden !important;
}

.project-chart canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* Modern Tables */
.modern-table {
    width: 100%;
    background: white;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.modern-table thead {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.modern-table th {
    padding: 0.75rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modern-table td {
    padding: 1rem 1.5rem;
    font-size: 0.875rem;
    color: var(--gray-900);
    border-bottom: 1px solid var(--gray-100);
}

.modern-table tbody tr:hover {
    background: var(--gray-50);
}

/* Project Selector Grid */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
}

.project-card {
    background: white;
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

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

.project-logo {
    width: 56px;
    height: 56px;
    border-radius: var(--border-radius);
    background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Modern Tabs */
.modern-tabs {
    display: flex;
    gap: 2rem;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 2rem;
}

.tab-button {
    padding: 1rem 0;
    background: none;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.tab-button:hover {
    color: var(--gray-700);
}

.tab-button.active {
    color: var(--primary-600);
    font-weight: 600;
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-600);
}

/* Loading States */
.skeleton {
    animation: skeleton-loading 1s linear infinite alternate;
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
}

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

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

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

/* Responsive Design */
@media (max-width: 1280px) {
    .metric-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .projects-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .dashboard-sidebar {
        position: fixed;
        left: -100%;
        height: 100vh;
        z-index: 50;
    }
    
    .dashboard-sidebar.mobile-open {
        left: 0;
    }
    
    .metric-cards {
        grid-template-columns: 1fr;
    }
    
    .projects-grid {
        grid-template-columns: 1fr;
    }
    
    .global-search {
        width: 100%;
    }
}

/* Predictions Section Styles */
.predictions-section {
    background: white;
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    margin-top: 2rem;
}

.predictions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-badge {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.predictions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.prediction-card {
    background: var(--gray-50);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
}

.prediction-card:hover {
    background: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.prediction-date {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-600);
    margin-bottom: 0.5rem;
}

.prediction-metric {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.prediction-label {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.prediction-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-900);
}

.confidence-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
}

.confidence-bar {
    flex: 1;
    height: 4px;
    background: var(--gray-200);
    border-radius: 2px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning-500), var(--success-500));
    border-radius: 2px;
    transition: width 0.3s ease;
}

.confidence-text {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
}

.risk-factors {
    margin-top: 1.5rem;
}

.risk-factors-header {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.risk-list {
    display: grid;
    gap: 0.75rem;
}

.risk-item {
    background: var(--error-50);
    border-left: 4px solid var(--error-500);
    padding: 0.75rem;
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    font-size: 0.875rem;
    color: var(--error-700);
}

.predictions-disclaimer {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--warning-50);
    border-radius: var(--border-radius);
    border: 1px solid var(--warning-200);
    font-size: 0.875rem;
    color: var(--warning-700);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.disclaimer-icon {
    color: var(--warning-600);
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.predictions-loading {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
}

.predictions-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top: 3px solid var(--primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.no-predictions {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

.no-predictions-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    color: var(--gray-400);
}

/* Notification Styles */
.srm-notification {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 9999;
    min-width: 300px;
    max-width: 400px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    animation: slideInRight 0.3s ease-out;
}

.notification-content {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.notification-message {
    font-size: 0.875rem;
    font-weight: 500;
    flex: 1;
}

.notification-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.notification-info {
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    color: var(--primary-700);
}

.notification-info .notification-close {
    color: var(--primary-700);
}

.notification-info .notification-close:hover {
    background: var(--primary-200);
}

.notification-success {
    background: var(--success-50);
    border: 1px solid var(--success-200);
    color: var(--success-700);
}

.notification-success .notification-close {
    color: var(--success-700);
}

.notification-success .notification-close:hover {
    background: var(--success-200);
}

.notification-error {
    background: var(--error-50);
    border: 1px solid var(--error-200);
    color: var(--error-700);
}

.notification-error .notification-close {
    color: var(--error-700);
}

.notification-error .notification-close:hover {
    background: var(--error-200);
}

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

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.p-4 { padding: 1rem; }
.rounded { border-radius: var(--border-radius); }
.shadow { box-shadow: var(--shadow); }
.hidden { display: none; }