/* ==========================================================================
   ZOHO BOOKS STYLE PROFESSIONAL LEFT NAVIGATION SIDEBAR
   Green Ray Nexus - Solar Monitoring & Management Portal
   ========================================================================== */

:root {
    --zoho-sidebar-w: 68px;
    --zoho-bg: #182030;
    --zoho-bg-hover: rgba(255, 255, 255, 0.08);
    --zoho-flyout-bg: #1c263c;
    --zoho-active-green: #10b981;
    --zoho-text-muted: #94a3b8;
    --zoho-text-light: #f8fafc;
    --zoho-border: rgba(255, 255, 255, 0.08);
}

/* Base Body Adjustment for Sidebar (using both class and :has for instant styling) */
body.has-zoho-sidebar,
body:has(#zohoAppSidebar),
body:has(#zohoAdminSidebar) {
    padding-left: var(--zoho-sidebar-w) !important;
    position: relative;
    box-sizing: border-box;
}

body.has-zoho-sidebar header,
body.has-zoho-sidebar .header-top,
body.has-zoho-sidebar .header-bottom,
body.has-zoho-sidebar main,
body.has-zoho-sidebar footer,
body.has-zoho-sidebar .dashboard-container {
    box-sizing: border-box;
}

/* Sidebar Fixed Container */
.zoho-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--zoho-sidebar-w);
    height: 100vh;
    background: var(--zoho-bg);
    border-right: 1px solid var(--zoho-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    z-index: 999999;
    user-select: none;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.25);
    padding: 10px 0;
    box-sizing: border-box;
}

/* Top Section: Logo */
.zoho-sidebar-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.zoho-logo-box {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
    border: 1.5px solid rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 10px rgba(16, 185, 129, 0.15);
    text-decoration: none;
    overflow: hidden;
}

.zoho-logo-box:hover {
    background: linear-gradient(135deg, #2a3850 0%, #1a2538 100%);
    border-color: #10b981;
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
}

.zoho-logo-box img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.zoho-sidebar-brand-title {
    font-size: 0.62rem;
    font-weight: 800;
    color: #f8fafc;
    letter-spacing: 0.8px;
    margin-top: 1px;
    text-align: center;
    text-transform: uppercase;
    font-family: inherit;
    line-height: 1.1;
}

.zoho-sidebar-brand-tag {
    font-size: 0.52rem;
    font-weight: 800;
    color: #10b981;
    letter-spacing: 0.5px;
    margin-top: 2px;
    margin-bottom: 12px;
    text-transform: uppercase;
    text-align: center;
    line-height: 1;
    white-space: nowrap;
}

/* Strict Role Separation: Solar Admin vs Master Super Admin */
body.is-superadmin .zoho-nav-item.epc-admin-only,
body.is-superadmin aside.sidebar li.epc-admin-only,
body.is-superadmin .epc-admin-only {
    display: none !important;
}
body.is-superadmin .zoho-nav-item.super-admin-only,
body.is-superadmin aside.sidebar li.super-admin-only {
    display: flex !important;
}

body.is-solaradmin .zoho-nav-item.super-admin-only,
body.is-solaradmin aside.sidebar li.super-admin-only,
body.is-solaradmin .super-admin-only {
    display: none !important;
}
body.is-solaradmin .zoho-nav-item.epc-admin-only,
body.is-solaradmin aside.sidebar li.epc-admin-only {
    display: flex !important;
}

/* Default state before JS runs: hide super-admin-only so solar admin sees zero flicker */
.zoho-nav-item.super-admin-only {
    display: none;
}

/* Vertical Menu Items List */
.zoho-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

/* Individual Nav Item */
.zoho-nav-item {
    position: relative;
    width: 56px;
    height: 52px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--zoho-text-muted);
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    box-sizing: border-box;
    padding: 6px 2px 4px;
}

.zoho-nav-item i {
    font-size: 1.22rem;
    margin-bottom: 3px;
    color: inherit;
    transition: transform 0.15s ease;
}

.zoho-nav-item span.zoho-label {
    font-size: 0.64rem;
    font-weight: 500;
    color: inherit;
    text-align: center;
    line-height: 1.05;
    letter-spacing: -0.2px;
    max-width: 52px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hover State */
.zoho-nav-item:hover {
    background: var(--zoho-bg-hover);
    color: var(--zoho-text-light);
}

.zoho-nav-item:hover i {
    transform: translateY(-1px);
}

/* Active State (Solid Emerald Green pill like Zoho Books) */
.zoho-nav-item.active {
    background: var(--zoho-active-green) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4) !important;
    font-weight: 600;
}

.zoho-nav-item.active i {
    color: #ffffff !important;
}

.zoho-nav-item.active span.zoho-label {
    color: #ffffff !important;
    font-weight: 700;
}

/* Bottom Actions */
.zoho-sidebar-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--zoho-border);
}

.zoho-nav-item.zoho-collapse-btn {
    height: 40px;
    opacity: 0.75;
}

.zoho-nav-item.zoho-collapse-btn:hover {
    opacity: 1;
}

/* ==========================================================================
   POPUP FLYOUT SUBMENU (Identical to Zoho Books Screenshot 2)
   ========================================================================== */
.zoho-flyout-menu {
    position: absolute;
    left: calc(var(--zoho-sidebar-w) + 4px);
    top: 0;
    min-width: 230px;
    background: var(--zoho-flyout-bg);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 10px rgba(0, 0, 0, 0.2);
    padding: 10px 8px;
    display: none;
    z-index: 1000000;
    pointer-events: auto;
    animation: zohoFlyoutFade 0.18s ease forwards;
}

@keyframes zohoFlyoutFade {
    from {
        opacity: 0;
        transform: translateX(-6px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Flyout Open on Item Hover or via Click */
.zoho-nav-item:hover .zoho-flyout-menu,
.zoho-nav-item.flyout-open .zoho-flyout-menu {
    display: block;
}

/* Invisible Bridge to prevent closing on mouse move */
.zoho-flyout-menu::before {
    content: '';
    position: absolute;
    top: 0;
    left: -12px;
    width: 14px;
    height: 100%;
    background: transparent;
}

/* Flyout Header Title */
.zoho-flyout-title {
    font-size: 0.72rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 10px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.zoho-flyout-title span.badge-pill {
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: normal;
    text-transform: none;
}

/* Submenu Links List */
.zoho-sub-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.zoho-sub-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 7px;
    color: #cbd5e1;
    font-size: 0.86rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.zoho-sub-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transform: translateX(2px);
}

.zoho-sub-link.active-sub {
    background: var(--zoho-active-green);
    color: #ffffff;
    font-weight: 700;
}

.zoho-sub-link .zoho-plus-btn {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    transition: background 0.15s ease;
}

.zoho-sub-link:hover .zoho-plus-btn {
    background: var(--zoho-active-green);
}

.zoho-sub-link.active-sub .zoho-plus-btn {
    background: rgba(255, 255, 255, 0.3);
}

/* Tooltip on simple items without flyout */
.zoho-nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(var(--zoho-sidebar-w) + 8px);
    background: #0f172a;
    color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 6px;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;
    z-index: 1000000;
    animation: zohoFlyoutFade 0.15s ease;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    :root {
        --zoho-sidebar-w: 0px !important;
    }

    body,
    body.has-zoho-sidebar,
    body:has(#zohoAppSidebar),
    body:has(#zohoAdminSidebar) {
        padding-left: 0 !important;
        margin-left: 0 !important;
        padding-bottom: 68px !important;
    }

    .zoho-sidebar {
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: 60px !important;
        flex-direction: row !important;
        border-right: none !important;
        border-top: 1px solid var(--zoho-border) !important;
        padding: 0 8px !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3) !important;
    }

    .zoho-logo-box,
    .zoho-sidebar-brand-title,
    .zoho-sidebar-brand-tag,
    .zoho-sidebar-bottom {
        display: none !important;
    }

    .zoho-sidebar-top {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
    }

    .zoho-menu {
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
        width: 100% !important;
        gap: 0 !important;
    }

    .zoho-nav-item {
        width: 50px !important;
        height: 48px !important;
        padding: 4px 2px !important;
    }

    .zoho-flyout-menu {
        position: fixed !important;
        bottom: 64px !important;
        left: 10px !important;
        right: 10px !important;
        top: auto !important;
        min-width: auto !important;
    }
}
