
/* =========================================================
   LEGAL MANAGEMENT SYSTEM
   File: css/menu.css
   Desktop: Left sidebar
   Mobile: Hamburger toggle + overlay
   Primary: #3b527c
   Dark: #283957
   ========================================================= */

:root {
    --menu-primary: #3b527c;
    --menu-dark: #283957;
    --menu-hover: #3b527c;
    --menu-active: #f80707;
    --menu-text: #ffffff;
    --menu-muted: #dce4f0;
    --menu-border: rgba(255, 255, 255, 0.14);

    --menu-width: 250px;
    --menu-mobile-width: 270px;
    --menu-header-height: 65px;
}

/* =========================================================
   GLOBAL LAYOUT
   ========================================================= */

* {
    box-sizing: border-box;
}

html {
    width: 100%;
    max-width: 100%;
}

body {
    margin: 0;
    min-width: 0;
    max-width: 100%;
}

.page-layout {
    display: flex;
    align-items: stretch;
    position: relative;
    width: 100%;
    min-width: 0;
    height: calc(100vh - var(--menu-header-height));
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.page-container,
.main-content {
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
}

/* =========================================================
   DESKTOP SIDEBAR
   ========================================================= */

#sidebar.sidebar {
    display: block;
    position: relative;
    flex: 0 0 var(--menu-width);
    width: var(--menu-width);
    min-width: var(--menu-width);
    max-width: var(--menu-width);

    align-self: stretch;
    min-height: calc(100vh - var(--menu-header-height));

    margin: 0;
    padding: 16px 10px;

    background: var(--menu-dark);
    color: var(--menu-text);

    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;

    box-sizing: border-box;
    z-index: 100;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;

    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;

    box-sizing: border-box;
}

/* =========================================================
   HOME AND GENERAL MENU LINKS
   ========================================================= */

#sidebar .menu-link {
    display: flex;
    align-items: center;
    gap: 11px;

    width: 100%;
    min-width: 0;
    min-height: 45px;

    margin: 0;
    padding: 11px 12px;

    border: 1px solid transparent;
    border-radius: 6px;

    background: transparent;
    color: var(--menu-text);

    text-decoration: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    text-align: left;

    white-space: normal;
    overflow-wrap: anywhere;

    transition: background 0.2s ease, color 0.2s ease;
}

#sidebar .menu-link:hover {
    background: var(--menu-hover);
    color: #ffffff;
}

#sidebar .menu-link.active {
    background: var(--menu-primary);
    color: #ffffff;
    border-left: 3px solid var(--menu-active);
    font-weight: 600;
}

#sidebar .menu-icon,
#sidebar .branch-menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 24px;
    width: 24px;
    min-width: 24px;

    color: inherit;
    font-size: 19px;
    line-height: 1;
}

#sidebar .menu-link > span:last-child {
    flex: 1 1 auto;
    min-width: 0;
}

/* =========================================================
   BRANCH MENU
   ========================================================= */

#sidebar .branch-menu-items {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
}

#sidebar .branch-main-menu {
    display: flex;
    flex-direction: column;
    gap: 5px;

    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;

    list-style: none;
}

#sidebar .branch-menu-item {
    display: block;
    position: relative;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

#sidebar .branch-menu-link {
    display: flex;
    align-items: center;
    gap: 10px;

    width: 100%;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 10px 12px;

    border: 1px solid transparent;
    border-radius: 6px;

    background: transparent;
    color: var(--menu-text);

    text-decoration: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    text-align: left;

    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;

    transition: background 0.2s ease;
}

#sidebar .branch-menu-link:hover,
#sidebar .branch-menu-item.dropdown-open > .branch-menu-link {
    background: var(--menu-primary);
    color: #ffffff;
}

#sidebar .branch-menu-text {
    display: block;
    flex: 1 1 auto;
    min-width: 0;

    color: inherit;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* =========================================================
   DROPDOWN ARROW
   ========================================================= */

#sidebar .branch-menu-item.has-dropdown > .branch-menu-link::after {
    content: "\25BE";
    display: inline-block;
    flex: 0 0 auto;
    margin-left: auto;
    color: inherit;
    font-size: 14px;
    transition: transform 0.2s ease;
}

#sidebar .branch-menu-item.has-dropdown.dropdown-open
> .branch-menu-link::after {
    transform: rotate(180deg);
}

/* =========================================================
   DROPDOWN SUBMENU
   ========================================================= */

#sidebar .branch-submenu,
#sidebar .branch-dropdown-menu,
#sidebar .branch-menu-item > ul {
    display: none;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 5px 0 5px 14px;
    list-style: none;
}

#sidebar .branch-menu-item.dropdown-open > .branch-submenu,
#sidebar .branch-menu-item.dropdown-open > .branch-dropdown-menu,
#sidebar .branch-menu-item.dropdown-open > ul {
    display: block;
}

#sidebar .branch-submenu li,
#sidebar .branch-dropdown-menu li,
#sidebar .branch-menu-item > ul > li {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

#sidebar .branch-submenu a,
#sidebar .branch-dropdown-menu a,
#sidebar .branch-menu-item > ul > li > a {
    display: flex;
    align-items: center;
    gap: 9px;

    width: 100%;
    min-width: 0;
    min-height: 40px;
    margin: 2px 0;
    padding: 9px 10px;

    border-radius: 5px;
    background: transparent;
    color: var(--menu-muted);

    text-decoration: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;

    white-space: normal;
    overflow-wrap: anywhere;
}

#sidebar .branch-submenu a:hover,
#sidebar .branch-dropdown-menu a:hover,
#sidebar .branch-menu-item > ul > li > a:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

/* =========================================================
   AREA MENU
   ========================================================= */

#sidebar .area-menu-items,
#sidebar .area-main-menu {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

#sidebar .area-main-menu {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0;
    padding: 0;
    list-style: none;
}

#sidebar .area-menu-item {
    width: 100%;
    min-width: 0;
    list-style: none;
}

/* =========================================================
   HAMBURGER BUTTON
   Hidden on desktop, visible on mobile
   ========================================================= */

.mobile-menu-toggle {
    display: none;

    align-items: center;
    justify-content: center;
    flex: 0 0 44px;

    width: 44px;
    min-width: 44px;
    height: 44px;

    margin: 0;
    padding: 0;

    border: 0;
    border-radius: 6px;

    background: var(--menu-dark);
    color: #ffffff;

    font-family: Arial, sans-serif;
    font-size: 28px;
    font-weight: 400;
    line-height: 1;

    cursor: pointer;
    touch-action: manipulation;

    position: relative;
    z-index: 1202;

    -webkit-appearance: none;
    appearance: none;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus-visible {
    background: var(--menu-primary);
    color: #ffffff;
    outline-offset: 2px;
}

.mobile-menu-toggle .menu-toggle-icon {
    display: inline-block;
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
    visibility: visible;
    opacity: 1;
}

/* =========================================================
   SIDEBAR OVERLAY
   ========================================================= */

#sidebar-overlay {
    display: none;
}

/* =========================================================
   MOBILE LAYOUT
   Uses .open to match the JavaScript
   ========================================================= */

@media screen and (max-width: 768px) {

    .page-layout {
        display: block;
        width: 100%;
        min-width: 0;
        min-height: calc(100vh - var(--menu-header-height));
        overflow-x: clip;
    }

    .mobile-menu-toggle {
        display: inline-flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        max-width: 85%;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 1000;
    }

    .sidebar-overlay.active {
        display: block;
    }
    
    #sidebar.sidebar {
        display: block !important;

        position: fixed !important;
        top: var(--menu-header-height);
        left: 0;
        right: auto;
        bottom: 0;

        width: var(--menu-mobile-width);
        min-width: 0;
        max-width: 85vw;

        height: auto;
        min-height: 0;

        margin: 0;
        padding: 14px 10px 24px;

        background: var(--menu-dark);
        color: #ffffff;

        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;

        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.20);

        z-index: 1200;

        transform: translateX(-105%);
        visibility: hidden;
        pointer-events: none;

        transition:
            transform 0.25s ease,
            visibility 0.25s ease;
    }

    /* Open class used by JavaScript */
    #sidebar.sidebar.open {
        display: block !important;
        transform: translateX(0);
        visibility: visible !important;
        pointer-events: auto !important;
    }

    #sidebar .sidebar-menu {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 5px;

        width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
    }

    #sidebar .menu-link,
    #sidebar .branch-menu-link {
        display: flex;
        align-items: center;

        width: 100%;
        min-width: 0;
        min-height: 44px;

        padding: 10px 11px;

        color: #ffffff;
        font-size: 14px;
        line-height: 1.6;

        white-space: normal;
        overflow-wrap: anywhere;
        word-break: normal;
    }

    #sidebar .menu-link > span:last-child,
    #sidebar .branch-menu-text {
        display: block;
        flex: 1 1 auto;
        min-width: 0;
        color: inherit;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    #sidebar .branch-menu-items,
    #sidebar .branch-menu-item,
    #sidebar .area-menu-items,
    #sidebar .area-menu-item {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    #sidebar .branch-main-menu,
    #sidebar .area-main-menu {
        display: flex;
        flex-direction: column;
        gap: 5px;

        width: 100%;
        margin: 0;
        padding: 0;

        list-style: none;
    }

    #sidebar .branch-submenu,
    #sidebar .branch-dropdown-menu,
    #sidebar .branch-menu-item > ul {
        padding-left: 12px;
    }

    #sidebar .branch-submenu a,
    #sidebar .branch-dropdown-menu a,
    #sidebar .branch-menu-item > ul > li > a {
        display: flex;
        width: 100%;
        min-width: 0;
        min-height: 42px;
        padding: 9px 10px;

        color: #e5eaf2;
        font-size: 13px;
        line-height: 1.5;

        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* Overlay */
    #sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;

        background: rgba(0, 0, 0, 0.45);

        opacity: 0;
        visibility: hidden;
        pointer-events: none;

        z-index: 1199;

        transition:
            opacity 0.25s ease,
            visibility 0.25s ease;
    }

    #sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    /* Prevent content from creating horizontal scrollbars */
    .page-container,
    .main-content {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        margin: 0;
        padding: 12px;
        overflow-wrap: anywhere;
    }

    .page-container img,
    .main-content img,
    .page-container canvas,
    .main-content canvas,
    .page-container iframe,
    .main-content iframe {
        max-width: 100%;
    }

    .table-wrapper {
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* =========================================================
   SMALL MOBILE DEVICES
   ========================================================= */

@media screen and (max-width: 480px) {

    :root {
        --menu-header-height: 60px;
        --menu-mobile-width: 260px;
    }

    #sidebar.sidebar {
        padding: 12px 8px 20px;
    }

    #sidebar .menu-link,
    #sidebar .branch-menu-link {
        gap: 9px;
        padding: 10px;
        font-size: 14px;
    }

    #sidebar .menu-icon,
    #sidebar .branch-menu-icon {
        flex-basis: 22px;
        width: 22px;
        min-width: 22px;
    }

    .mobile-menu-toggle {
        flex-basis: 42px;
        width: 42px;
        min-width: 42px;
        height: 42px;
    }

    .page-container,
    .main-content {
        padding: 10px;
    }
}

/* =========================================================
   ACCESSIBILITY
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    #sidebar,
    #sidebar *,
    #sidebar-overlay,
    .mobile-menu-toggle {
        transition: none !important;
        animation: none !important;
    }
}

/* ==========================================
   SIDEBAR AND TABLE SCROLL CONTROL
========================================== */

/* Desktop sidebar: no separate scrollbar */
@media screen and (min-width: 769px) {
    #sidebar.sidebar {
        height: 100%;
        min-height: 0;
        overflow: hidden !important;
    }
}

/* Main content: only vertical scrollbar */
.page-container {
    overflow-y: auto !important;
    min-height: 0;
}

/* Table: horizontal scrolling only */
.page-container .table-wrapper {
    max-width: 100%;
    min-width: 0;
    overflow-x: auto !important;
    overflow-y: hidden !important;
}

/* Mobile layout */
@media screen and (max-width: 768px) {
    .page-layout {
        height: calc(100vh - var(--menu-header-height));
        min-height: 0;
        overflow: hidden !important;
    }

    .page-container {
        height: 100%;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    #sidebar.sidebar {
        height: auto;
        min-height: 0;
        overflow-y: auto;
    }
}


.branch-menu-link.active,
.menu-link.active,
.branch-dropdown li a.active {
    border-left: 4px solid #f80707 !important;
    font-weight: 700;
    padding-left: 12px;
}

/* ACTIVE DROPDOWN PARENT */
.branch-menu-item.dropdown-open > .branch-menu-link {
    border-left: 4px solid #f80707 !important;
}

/* SMOOTH EFFECT */
.branch-menu-link,
.branch-dropdown li a,
.menu-link {
    transition: all 0.2s ease;
}
