/**
 * 🎨 LIGHT & DARK THEME DESIGN SYSTEM TOKENS
 * File: public/css/light-theme.css
 * Enterprise standard: CSS Custom Properties for theme tokens
 */

:root,
html:not(.dark),
html.light {
    --theme-bg-main: #f8fafc;
    --theme-bg-surface: #ffffff;
    --theme-bg-card: #ffffff;
    --theme-border: #e2e8f0;
    --theme-border-subtle: #f1f5f9;
    --theme-text-main: #0f172a;
    --theme-text-muted: #64748b;
    --theme-text-subtle: #94a3b8;
    --theme-bg-elevated: #ffffff;
    --theme-bg-muted: #f8fafc;
    --theme-primary: #4f46e5;
    --theme-primary-hover: #4338ca;
    --theme-on-primary: #ffffff;
    --theme-danger: #be123c;
    --theme-danger-hover: #9f1239;
    --theme-on-danger: #ffffff;
    --theme-focus-ring: rgba(79, 70, 229, 0.2);
    --theme-shadow-soft: 0 18px 45px rgba(15, 23, 42, 0.08);
    --theme-shadow-float: 0 24px 60px rgba(15, 23, 42, 0.14);
    --theme-overlay: rgba(15, 23, 42, 0.58);
    --theme-success-soft: rgba(16, 185, 129, 0.12);
    --theme-danger-soft: rgba(244, 63, 94, 0.1);
    --theme-info-soft: rgba(14, 165, 233, 0.1);

    /* Category Light Card Backgrounds & Borders */
    --card-imei-bg: rgba(236, 253, 245, 0.7);
    --card-imei-border: rgba(167, 243, 208, 0.8);
    --card-imei-icon-bg: rgba(209, 250, 229, 0.8);
    --card-imei-icon-text: #059669;

    --card-server-bg: rgba(255, 241, 242, 0.7);
    --card-server-border: rgba(254, 205, 211, 0.8);
    --card-server-icon-bg: rgba(255, 228, 230, 0.8);
    --card-server-icon-text: #e11d48;

    --card-remote-bg: rgba(240, 249, 255, 0.7);
    --card-remote-border: rgba(186, 230, 253, 0.8);
    --card-remote-icon-bg: rgba(224, 242, 254, 0.8);
    --card-remote-icon-text: #0284c7;

    --card-shop-bg: rgba(255, 251, 235, 0.7);
    --card-shop-border: rgba(254, 243, 199, 0.8);
    --card-shop-icon-bg: rgba(254, 243, 199, 0.8);
    --card-shop-icon-text: #d97706;

    /* Chart Grid, Axis & Series Colors */
    --chart-grid-border: #cbd5e1;
    --chart-label-color: #64748b;
    --chart-color-imei: #20b2aa;
    --chart-color-server: #ff5353;
    --chart-color-remote: #00b4d8;
    --chart-color-shop: #f4a261;
}

html.dark {
    --theme-bg-main: #0f172a;
    --theme-bg-surface: #1e293b;
    --theme-bg-card: rgba(30, 41, 59, 0.8);
    --theme-border: #334155;
    --theme-border-subtle: #1e293b;
    --theme-text-main: #f8fafc;
    --theme-text-muted: #94a3b8;
    --theme-text-subtle: #64748b;
    --theme-bg-elevated: #111b30;
    --theme-bg-muted: #0b1324;
    --theme-primary: #818cf8;
    --theme-primary-hover: #6366f1;
    --theme-on-primary: #ffffff;
    --theme-danger: #fb7185;
    --theme-danger-hover: #f43f5e;
    --theme-on-danger: #ffffff;
    --theme-focus-ring: rgba(129, 140, 248, 0.24);
    --theme-shadow-soft: 0 20px 50px rgba(0, 0, 0, 0.24);
    --theme-shadow-float: 0 28px 70px rgba(0, 0, 0, 0.42);
    --theme-overlay: rgba(2, 6, 23, 0.72);
    --theme-success-soft: rgba(52, 211, 153, 0.1);
    --theme-danger-soft: rgba(251, 113, 133, 0.1);
    --theme-info-soft: rgba(56, 189, 248, 0.1);

    /* Category Dark Card Backgrounds & Borders */
    --card-imei-bg: rgba(15, 23, 42, 0.8);
    --card-imei-border: rgba(16, 185, 129, 0.2);
    --card-imei-icon-bg: rgba(16, 185, 129, 0.1);
    --card-imei-icon-text: #34d399;

    --card-server-bg: rgba(15, 23, 42, 0.8);
    --card-server-border: rgba(244, 63, 94, 0.2);
    --card-server-icon-bg: rgba(244, 63, 94, 0.1);
    --card-server-icon-text: #fb7185;

    --card-remote-bg: rgba(15, 23, 42, 0.8);
    --card-remote-border: rgba(14, 165, 233, 0.2);
    --card-remote-icon-bg: rgba(14, 165, 233, 0.1);
    --card-remote-icon-text: #38bdf8;

    --card-shop-bg: rgba(15, 23, 42, 0.8);
    --card-shop-border: rgba(245, 158, 11, 0.2);
    --card-shop-icon-bg: rgba(245, 158, 11, 0.1);
    --card-shop-icon-text: #fbbf24;

    /* Chart Grid & Axis Colors */
    --chart-grid-border: #334155;
    --chart-label-color: #94a3b8;
    --chart-color-imei: #20b2aa;
    --chart-color-server: #ff5353;
    --chart-color-remote: #00b4d8;
    --chart-color-shop: #f4a261;
}

/* 📊 APEXCHARTS DYNAMIC LIGHT / DARK TOOLTIP POPUP */
.apexcharts-canvas .apexcharts-tooltip {
    background: var(--theme-bg-surface, #ffffff) !important;
    border: 1px solid var(--theme-border, #e2e8f0) !important;
    border-radius: 12px !important;
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.15) !important;
    color: var(--theme-text-main, #0f172a) !important;
    z-index: 99999 !important;
    overflow: hidden !important;
    pointer-events: none !important;
    transition: opacity 0.15s ease-in-out !important;
}

html.dark .apexcharts-canvas .apexcharts-tooltip {
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.6) !important;
}

.apexcharts-canvas .apexcharts-tooltip:not(.apexcharts-active) {
    opacity: 0 !important;
}

.apexcharts-canvas .apexcharts-tooltip-title {
    background: var(--theme-bg-main, #f8fafc) !important;
    border-bottom: 1px solid var(--theme-border, #e2e8f0) !important;
    font-weight: 700 !important;
    font-size: 12px !important;
    padding: 8px 12px !important;
    color: var(--theme-text-main, #0f172a) !important;
}

.apexcharts-canvas .apexcharts-tooltip-series-group {
    padding: 6px 12px !important;
    background: var(--theme-bg-surface, #ffffff) !important;
}

.apexcharts-canvas .apexcharts-tooltip-text-y-value {
    font-weight: 800 !important;
    color: var(--theme-text-main, #0f172a) !important;
}

/* 🚀 SIDEBAR MEGA FLYOUT DROPDOWN (Matches User Screenshot) */
.sidebar-mega-menu {
    background-color: var(--theme-bg-surface, #ffffff);
    border: 1px solid var(--theme-border, #e2e8f0);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15), 0 10px 20px -5px rgba(0, 0, 0, 0.05);
    color: var(--theme-text-main, #0f172a);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

html.dark .sidebar-mega-menu {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.sidebar-mega-item {
    color: var(--theme-text-main, #0f172a);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
    transition: all 0.15s ease-in-out;
}

.sidebar-mega-item:hover {
    background-color: var(--theme-border-subtle, #f1f5f9);
    color: var(--theme-text-main, #0f172a);
    transform: translateX(3px);
}

html.dark .sidebar-mega-item:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

/* Desktop Flyout positioning & hover trigger */
@media (min-width: 1024px) {
    .nav-group {
        position: relative;
    }

    .nav-group .sidebar-mega-menu {
        position: absolute;
        left: calc(100% + 8px);
        top: -6px;
        width: 480px;
        max-height: calc(100vh - 32px);
        overflow-y: auto;
        z-index: 99999;
        opacity: 0;
        visibility: hidden;
        transform: translateX(-8px) scale(0.97);
        transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s ease;
        pointer-events: none;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    }

    /* 🎯 Smart flyout alignment for items near the bottom of sidebar to prevent screen clipping */
    .nav-group:nth-last-child(-n+7) .sidebar-mega-menu {
        top: auto;
        bottom: -6px;
    }

    /* Invisible hover bridge between menu link and flyout box */
    .nav-group::before {
        content: '';
        position: absolute;
        left: 100%;
        top: 0;
        bottom: 0;
        width: 16px;
        z-index: 99998;
    }

    .nav-group:hover .sidebar-mega-menu,
    .nav-group .sidebar-mega-menu:hover {
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateX(0) scale(1) !important;
        pointer-events: auto !important;
    }
}
