/* =========================================================
   LEFT SIDEBAR NAVIGATION (overrides the old horizontal .mainnav)
   - Desktop: fixed left sidebar, collapsible to icon-only width
   - Mobile (<=768px): off-canvas drawer, toggled by .menu-toggle
   ========================================================= */

:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    --sidebar-bg: #1e1e1e;
    --sidebar-bg-hover: #333333;
    --sidebar-border: #2c2c2c;
    --sidebar-text: #e6e6e6;
    --sidebar-accent: #0a75c7;
}

/* Push the page header/content/footer to the right of the sidebar on desktop */
body {
    transition: padding-left 0.3s ease-in-out;
}

@media (min-width: 769px) {
    body {
        padding-left: var(--sidebar-width);
    }

    body.sidebar-collapsed {
        padding-left: var(--sidebar-collapsed-width);
    }
}

/* ---- Sidebar container ---- */
.mainnav {
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    border-bottom: none;
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1040;
    transition: width 0.25s ease-in-out;
    padding-top: 0;
}

/* Collapsed (icon-only) state on desktop */
.mainnav.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* ---- Sidebar header: brand/title + collapse toggle ---- */
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    background: #161616;
    flex-shrink: 0;
}

.sidebar-head .sidebar-title {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}

.mainnav.collapsed .sidebar-head .sidebar-title {
    opacity: 0;
    width: 0;
}

.sidebar-collapse-btn {
    background: transparent;
    border: 1px solid #444;
    color: #fff;
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s, transform 0.25s ease-in-out;
}

.sidebar-collapse-btn:hover {
    background: var(--sidebar-accent);
    border-color: var(--sidebar-accent);
}

.mainnav.collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

/* ---- Menu list ---- */
.mainnav ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    margin: 0;
    width: 100%;
}

.mainnav ul li {
    position: relative;
    border-left: none;
    width: 100%;
}

.mainnav ul li a {
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 11.5px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    white-space: nowrap;
}

.mainnav ul li a i.fa-caret-down {
    margin-left: auto;
    font-size: 11px;
    transition: transform 0.2s ease-in-out;
}

.mainnav ul li.open > a > i.fa-caret-down {
    transform: rotate(180deg);
}

/* Leading icon for each top-level item (added in HTML via data, falls back to a generic dot) */
.mainnav > ul > li > a::before {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    color: #9fd3ff;
}

.mainnav ul li:hover,
.mainnav ul li:hover > a {
    background: var(--sidebar-bg-hover);
}

/* Hide text labels when collapsed; keep icons centered */
.mainnav.collapsed ul li a {
    justify-content: center;
    padding: 11px 0;
}

.mainnav.collapsed ul li a span.label,
.mainnav.collapsed ul li a i.fa-caret-down {
    display: none;
}

/* ---- Submenus: inline accordion-style (no more hover flyouts) ---- */
.mainnav .submenu {
    position: static;
    display: none;
    list-style: none;
    background: #161616;
    width: 100%;
    padding: 0;
    margin: 0;
    box-shadow: none;
    z-index: auto;
}

.mainnav ul li.open > .submenu {
    display: block !important;
}

.mainnav .submenu li a {
    padding-left: 40px;
    font-size: 13px;
    color: #cfcfcf;
}

.mainnav .submenu .submenu li a {
    padding-left: 60px;
}

.mainnav .submenu .submenu {
    position: static;
    width: 100%;
    left: 0;
    top: 0;
}

/* When collapsed, submenus fly out to the right as a popover instead of inline.
   Positioned dynamically via JS (top = matches the hovered <li>), so it always
   lines up beside the item instead of jumping to the top of the page. */
.mainnav.collapsed ul li.open > .submenu {
    display: none !important;
}

.mainnav.collapsed .submenu.flyout-open {
    display: block !important;
    position: fixed;
    width: 220px;
    background: #1e1e1e;
    box-shadow: 4px 4px 12px rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 6px 0;
    z-index: 1060;
}

.mainnav.collapsed .submenu li a {
    padding-left: 16px;
}

.mainnav.collapsed .submenu .submenu li a {
    padding-left: 28px;
}

/* Nested (2nd level) flyout when collapsed: opens beside its parent flyout */
.mainnav.collapsed .submenu .submenu.flyout-open {
    display: block !important;
    position: fixed;
    width: 220px;
    background: #1e1e1e;
    box-shadow: 4px 4px 12px rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 6px 0;
    z-index: 1061;
}

/* ---- Mobile: off-canvas drawer (preserves existing hamburger behavior) ----
   IMPORTANT: responsive.css also defines a conflicting .mainnav block for
   this same breakpoint (display:none/flex toggling, different left/width/
   z-index values). This file is loaded AFTER responsive.css, and several
   properties below are marked !important to guarantee these rules win
   regardless of load order if someone re-shuffles the <link> tags later. */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        width: 100%;
    }

    body {
        padding-left: 0 !important;
    }

    .mainnav {
        display: flex !important; /* responsive.css sets display:none by default */
        left: -280px !important;
        width: 250px !important;
        height: 100% !important;
        top: 0 !important;
        opacity: 0;
        box-shadow: none;
        z-index: 1040 !important;
        transition: left 0.35s ease-in-out, opacity 0.3s ease-in-out;
        pointer-events: none; /* fully inert while off-canvas, even though display stays flex */
    }

    .mainnav.active {
        left: 0 !important;
        opacity: 1;
        box-shadow: 4px 0 18px rgba(0, 0, 0, 0.35);
        pointer-events: auto;
    }

    .mainnav.collapsed {
        width: 250px !important; /* collapse toggle is desktop-only; ignore on mobile */
    }

    .sidebar-collapse-btn {
        display: none;
    }

    .sidebar-head {
        display: none;
    }

    .mainnav ul {
        padding-top: 90px;
    }

    .mainnav.collapsed ul li a span.label,
    .mainnav.collapsed ul li a i.fa-caret-down {
        display: flex;
    }

    .mainnav.collapsed ul li a {
        justify-content: flex-start;
        padding: 11px 16px;
    }

    .mainnav ul li a {
        font-size: 13.5px !important; /* responsive.css drops this to 8px in one rule */
    }

    /* Dark backdrop behind the open drawer, covering all page content
       (header, top-menu, dashboard, footer) so nothing shows/overlaps
       through or beside the sidebar while it's open. */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1035; /* below .mainnav (1040), above everything else */
    }

    .sidebar-backdrop.active {
        display: block;
    }

    /* Prevent the page from scrolling behind the drawer while it's open */
    body.nav-open {
        overflow: hidden;
    }
}

@media (min-width: 769px) {
    .menu-toggle {
        display: none !important;
    }

    .sidebar-backdrop {
        display: none !important;
    }
}

/* =========================================================
   STICKY FOOTER — always sits at the bottom of the viewport
   when page content is short, and after content when it's tall.
   Works at all resolutions since body is already a flex column
   with min-height: 100vh.
   ========================================================= */
.footer {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    width: 100%;
    z-index: 900;
}

/* =========================================================
   "My Account" top-right menu — click to open, not mouse-over.
   styles.css has a hover rule (.top-menu-item:hover .top-submenu)
   that forces it open on mouse-over; this overrides it so only
   the JS click handler controls visibility.
   Also fixes z-index: styles.css gives .top-submenu no explicit
   z-index, so it was rendering BEHIND the .overlay (z-index 999)
   once the overlay appeared — making the menu look invisible/
   delayed until scrolled. Now it always sits above the overlay.
   ========================================================= */
.top-menu-item:hover .top-submenu {
    display: none !important;
}

.top-menu-item .top-submenu.open {
    display: block !important;
    z-index: 1100 !important;
    transition: none !important;
    animation: none !important;
}

.top-menu-item {
    z-index: 1100;
}

.overlay {
    transition: none !important;
}

/* =========================================================
   Financial Year dropdown — top-right corner, in the top-menu bar
   ========================================================= */
.top-menu-fy {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
}

.top-menu-fy label {
    color: #ffffff;
    font-size: 13px;
    margin: 0;
    white-space: nowrap;
}

.top-menu-fy select {
    background: #ffffff;
    color: #1e1e1e;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
    cursor: pointer;
    height: auto;
}

.top-menu-fy select:focus {
    outline: 2px solid rgba(255, 255, 255, 0.6);
}

@media (max-width: 768px) {
    .top-menu {
        flex-wrap: wrap;
        padding: 20px 10px;
    }
}
@media (max-width: 768px) {
    .top-menu-fy {
        margin-right: 8px;
        /* margin-top: 10px; */
        /* margin-bottom: 10px; */
    }
}

/* =========================================================
   Footer social icons — 5px spacing + "Follow Us" label
   ========================================================= */
.social-icons {
    gap: 5px !important;
}

.social-icons i {
    padding-left: 0 !important; /* gap now handles spacing, avoid double gaps */
}

.social-icons-label {
    color: inherit;
    font-size: 10pt;
    margin-right: 4px;
    white-space: nowrap;
}

/* =========================================================
   Dashboard title moved into .top-menu (left-aligned),
   replacing the standalone .dashboard-title <h2> that used
   to sit above the page content.
   ========================================================= */
.top-menu {
    justify-content: space-between !important;
}

.top-menu-page-title {
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    text-align: left;
    white-space: nowrap;
}

.top-menu-right {
    display: flex;
    align-items: center;
    gap: 0;
}

@media (max-width: 768px) {
    .top-menu {
        flex-wrap: wrap;
    }

    .top-menu-page-title {
        font-size: 14px;
        flex: 1 0 100%;
        margin-bottom: 6px;
    }

    .top-menu-right {
        flex-wrap: wrap;
        row-gap: 8px;
        justify-content: center;
        width: 100%;
    }
}

/* =========================================================
   Dashboard page tweaks
   ========================================================= */

/* Card spacing — dashboard page only (single .card.h-auto on this page) */
.card.h-auto {
    margin-top: 20px;
}

@media (max-width: 768px) {
    /* Give the page content 10px breathing room on mobile */
    .container {
        padding-left: 10px !important;
        padding-right: 10px !important;.mainnav ul li a
    }

    /* Center the "Dashboard" page title on mobile */
    .top-menu-page-title {
        text-align: center;
        width: 100%;
    }

    /* Financial Year dropdown: 50% width, centered on mobile */
    .top-menu-fy {
        width: 100%;
        justify-content: center;
    }

    .top-menu-fy select {
        width: 50%;
    }
}

/* =========================================================
   Search card "Financial Year" field (#companystate) —
   center the whole column (label + dropdown) on mobile,
   dropdown at 50% width
   ========================================================= */
@media (max-width: 768px) {
    .col-md-4.col-12.mb-3.no-padding-right {
        text-align: center;
    }

    .col-md-4.col-12.mb-3.no-padding-right .dropdown {
        width: 50%;
        margin: 0 auto;
    }

    #companystate {
        width: 100%;
    }
}