/* ══════════════════════════════════════════════════════════════
   ForecastAI Dashboard — Premium Dark Mode Stylesheet
   Multi-Page SPA Layout
   ══════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─── */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --bg-card-hover: #222840;
    --bg-glass: rgba(26, 31, 46, 0.7);
    --border-color: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(99, 102, 241, 0.15);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-blue: #6366f1;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-pink: #ec4899;
    --accent-red: #ef4444;

    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-success: linear-gradient(135deg, #10b981, #06b6d4);
    --gradient-warm: linear-gradient(135deg, #f59e0b, #ec4899);
    --gradient-cool: linear-gradient(135deg, #06b6d4, #6366f1);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);

    --sidebar-width: 240px;
    --header-height: 70px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ══════════════════ SIDEBAR ══════════════════ */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: transform var(--transition-smooth);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px 24px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.brand-icon {
    width: 42px; height: 42px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.brand-text {
    font-size: 1.25rem; font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem; font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0; top: 0;
    height: 100%; width: 3px;
    background: var(--gradient-primary);
    border-radius: 0 4px 4px 0;
    transform: scaleY(0);
    transition: transform var(--transition-smooth);
}

.nav-item:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent-blue);
}

.nav-item.active::before { transform: scaleY(1); }

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.footer-badge {
    display: inline-flex; align-items: center;
    padding: 6px 14px;
    background: var(--gradient-primary);
    border-radius: 20px;
    font-size: 0.7rem; font-weight: 600;
    letter-spacing: 1px; text-transform: uppercase;
    color: white;
}

/* ══════════════════ MAIN CONTENT ══════════════════ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* ─── Header ─── */
.dashboard-header {
    position: sticky;
    top: 0; z-index: 50;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: rgba(10, 14, 23, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

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

.menu-toggle {
    display: none;
    background: none; border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}
.menu-toggle:hover { background: rgba(255, 255, 255, 0.05); }

.header-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.5px; }
.header-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.status-pill {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    font-size: 0.78rem; color: var(--text-secondary); font-weight: 500;
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent-orange);
    animation: pulse 2s infinite;
}

.status-pill.connected .status-dot { background: var(--accent-green); animation: none; }
.status-pill.error .status-dot { background: var(--accent-red); animation: none; }

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

/* ─── Loading Overlay ─── */
.loading-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(10, 14, 23, 0.92);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(8px);
    transition: opacity 0.5s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loader { text-align: center; }
.loader-ring {
    width: 56px; height: 56px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader p { color: var(--text-secondary); font-size: 0.9rem; }

/* ══════════════════ PAGE SYSTEM ══════════════════ */
.page {
    display: none;
    padding: 32px;
    flex: 1;
    animation: pageIn 0.35s ease forwards;
}

.page.active {
    display: block;
}

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

/* ══════════════════ KPI CARDS ══════════════════ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex; align-items: center; gap: 16px;
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

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

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-glow);
}
.kpi-card:hover::before { opacity: 1; }

.kpi-sales::before { background: var(--gradient-primary); }
.kpi-profit::before { background: var(--gradient-success); }
.kpi-orders::before { background: var(--gradient-warm); }
.kpi-aov::before { background: var(--gradient-cool); }
.kpi-margin::before { background: linear-gradient(135deg, var(--accent-green), var(--accent-purple)); }
.kpi-quantity::before { background: linear-gradient(135deg, var(--accent-orange), var(--accent-red)); }

.kpi-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.kpi-sales .kpi-icon { background: rgba(99, 102, 241, 0.15); color: var(--accent-blue); }
.kpi-profit .kpi-icon { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.kpi-orders .kpi-icon { background: rgba(245, 158, 11, 0.15); color: var(--accent-orange); }
.kpi-aov .kpi-icon { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.kpi-margin .kpi-icon { background: rgba(139, 92, 246, 0.15); color: var(--accent-purple); }
.kpi-quantity .kpi-icon { background: rgba(236, 72, 153, 0.15); color: var(--accent-pink); }

.kpi-content { display: flex; flex-direction: column; gap: 4px; }
.kpi-label {
    font-size: 0.75rem; font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.kpi-value { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; }

/* ══════════════════ CHART CARDS ══════════════════ */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    transition: border-color var(--transition-smooth);
}
.chart-card:hover { border-color: var(--border-glow); }

.chart-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap; gap: 12px;
}
.chart-header h3 { font-size: 1rem; font-weight: 600; color: var(--text-primary); }

.chart-wrapper { position: relative; height: 320px; }
.chart-wrapper-xl { height: 420px; }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}
.chart-grid .chart-card { margin-bottom: 0; }

.chart-legend-custom { display: flex; gap: 20px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-historical { background: var(--accent-blue); }
.legend-forecast { background: var(--accent-orange); }

/* ══════════════════ DATA TABLE ══════════════════ */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table thead th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}
.data-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
}
.data-table tbody tr:hover td {
    background: rgba(99, 102, 241, 0.04);
    color: var(--text-primary);
}
.trend-up { color: var(--accent-green); font-weight: 600; }
.trend-down { color: var(--accent-red); font-weight: 600; }

/* ══════════════════ MODEL INFO CARD ══════════════════ */
.model-info-card {
    background: var(--bg-card);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 24px;
}

.model-info-header {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.model-badge {
    display: inline-flex; align-items: center;
    padding: 8px 20px;
    background: var(--gradient-primary);
    border-radius: 20px;
    font-size: 0.85rem; font-weight: 600;
    color: white;
}

.model-info-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.model-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.stat-label {
    font-size: 0.7rem; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.4rem; font-weight: 800;
    letter-spacing: -0.5px;
}

.stat-value.good { color: var(--accent-green); }
.stat-value.moderate { color: var(--accent-orange); }
.stat-value.poor { color: var(--accent-red); }

/* ══════════════════ RESPONSIVE ══════════════════ */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .page { padding: 20px 16px; }
    .dashboard-header { padding: 0 16px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .chart-wrapper, .chart-wrapper-xl { height: 260px; }
    .header-title { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-card { padding: 18px; }
    .kpi-value { font-size: 1.25rem; }
}

/* ─── Mobile sidebar overlay ─── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}
.sidebar-overlay.active { display: block; }
