/* ═══════════════════════════════════════════════════════════════
   Stock Data Intelligence Dashboard — Styles
   Premium dark theme with glassmorphism, gradients, and micro-animations
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Variables / Design Tokens ─── */
:root {
    /* Background & Surface */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-hover: rgba(255, 255, 255, 0.06);
    
    /* Accent Colors */
    --accent-primary: #6366f1;
    --accent-primary-light: #818cf8;
    --accent-secondary: #06b6d4;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --accent-purple: #a855f7;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #6366f1, #06b6d4);
    --gradient-green: linear-gradient(135deg, #10b981, #059669);
    --gradient-red: linear-gradient(135deg, #ef4444, #dc2626);
    --gradient-amber: linear-gradient(135deg, #f59e0b, #d97706);
    --gradient-bg: linear-gradient(135deg, #0a0e17 0%, #111827 50%, #0f172a 100%);
    
    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #818cf8;
    
    /* Borders */
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
    
    /* Spacing */
    --sidebar-width: 320px;
    --header-height: 70px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gradient-bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ─── Background Decorations ─── */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(6, 182, 212, 0.06) 0%, transparent 50%),
                radial-gradient(circle at 40% 80%, rgba(168, 85, 247, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
    animation: bgShift 20s ease-in-out infinite;
}

@keyframes bgShift {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-2%, -1%); }
}

/* ─── Loading Screen ─── */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 20px;
}

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

.loading-text {
    font-size: 1.1rem;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

/* ─── Layout ─── */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.sidebar-logo .logo-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: var(--shadow-glow);
}

.sidebar-logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-logo .subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Search Input */
.search-container {
    position: relative;
}

.search-container input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    transition: var(--transition-fast);
    outline: none;
}

.search-container input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-container input::placeholder {
    color: var(--text-muted);
}

.search-container .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Company List */
.company-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.company-list::-webkit-scrollbar {
    width: 4px;
}

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

.company-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.company-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.company-item:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-color);
}

.company-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
}

.company-item .company-info {
    flex: 1;
    min-width: 0;
}

.company-item .company-symbol {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.company-item .company-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.company-item .company-price {
    text-align: right;
}

.company-item .price-value {
    font-weight: 600;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}

.company-item .price-change {
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.price-up { color: var(--accent-green); }
.price-down { color: var(--accent-red); }

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-footer .data-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-footer .status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    margin-right: 6px;
    animation: pulse 2s ease-in-out infinite;
}

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

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    min-height: 100vh;
}

/* ─── Header Bar ─── */
.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-bar h2 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-bar .header-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 2px;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 4px;
    border: 1px solid var(--border-color);
}

.nav-tab {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.nav-tab.active {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: var(--transition-normal);
}

.card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title .icon {
    font-size: 1.1rem;
}

/* ─── Stats Grid ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: var(--transition-normal);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card.accent-indigo::before { background: var(--gradient-primary); }
.stat-card.accent-green::before { background: var(--gradient-green); }
.stat-card.accent-red::before { background: var(--gradient-red); }
.stat-card.accent-amber::before { background: var(--gradient-amber); }

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.stat-card .stat-change {
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 4px;
}

/* ─── Charts Container ─── */
.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
}

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

/* ─── Time Filter Buttons ─── */
.time-filters {
    display: flex;
    gap: 6px;
}

.time-btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
}

.time-btn:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.time-btn.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* ─── Compare Section ─── */
.compare-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.compare-select {
    padding: 10px 14px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    min-width: 180px;
    outline: none;
    cursor: pointer;
    transition: var(--transition-fast);
}

.compare-select:focus {
    border-color: var(--accent-primary);
}

.compare-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-compare {
    padding: 10px 24px;
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.btn-compare:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.btn-compare:active {
    transform: translateY(0);
}

/* Compare Results */
.compare-results {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.compare-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.compare-metric .metric-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.compare-metric .metric-value {
    font-weight: 600;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

/* Correlation Badge */
.correlation-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    font-size: 0.85rem;
    margin-top: 12px;
}

.correlation-value {
    font-weight: 700;
    color: var(--accent-primary-light);
}

/* ─── Insights Grid ─── */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.insight-list {
    list-style: none;
}

.insight-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    cursor: pointer;
}

.insight-item:hover {
    background: var(--bg-glass-hover);
}

.insight-item .rank {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 12px;
    flex-shrink: 0;
}

.insight-item .stock-info {
    flex: 1;
    min-width: 0;
}

.insight-item .stock-symbol {
    font-weight: 600;
    font-size: 0.88rem;
}

.insight-item .stock-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.insight-item .change-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.change-badge.positive {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}

.change-badge.negative {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

/* ─── Prediction Section ─── */
.prediction-banner {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.1));
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.prediction-banner .banner-icon {
    font-size: 1.5rem;
}

.prediction-banner .banner-text {
    flex: 1;
}

.prediction-banner .banner-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.prediction-banner .banner-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Model Metrics */
.model-metrics {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.metric-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    font-size: 0.82rem;
}

.metric-pill .metric-key {
    color: var(--text-muted);
}

.metric-pill .metric-val {
    font-weight: 600;
    color: var(--accent-primary-light);
}

/* ─── Sector Chart ─── */
.sector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.sector-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    transition: var(--transition-fast);
}

.sector-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-glow);
}

.sector-name {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.sector-return {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.sector-companies {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ─── Correlation Matrix ─── */
.matrix-container {
    overflow-x: auto;
    margin-top: 16px;
}

.corr-table {
    border-collapse: collapse;
    font-size: 0.72rem;
    width: 100%;
}

.corr-table th,
.corr-table td {
    padding: 8px 6px;
    text-align: center;
    border: 1px solid var(--border-color);
    min-width: 55px;
}

.corr-table th {
    background: var(--bg-glass);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.7rem;
    position: sticky;
    top: 0;
}

.corr-table td {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* ─── View Sections ─── */
.view-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: block;
}

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

/* ─── Responsive ─── */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 8px;
}

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px 16px;
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        display: none;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .compare-results {
        grid-template-columns: 1fr;
    }
    
    .insights-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .header-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-container {
        height: 280px;
    }
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.85rem;
}

/* ─── Tooltip ─── */
.tooltip-custom {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-lg) !important;
    color: var(--text-primary) !important;
    font-family: 'Inter', sans-serif !important;
    padding: 10px 14px !important;
}

/* ─── Summary Table ─── */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.summary-section {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
}

.summary-section h4 {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.summary-row:last-child {
    border-bottom: none;
}

.summary-row .label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.summary-row .value {
    font-weight: 600;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}

/* ─── Refresh Button ─── */
.btn-refresh {
    padding: 8px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-refresh:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
    background: var(--bg-glass-hover);
}
