/* ============================================
   SIDEBAR & OVERLAY
   ============================================ */

/* Sidebar Overlay (backdrop) - starts below header */
.sidebar-overlay {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100vh - 60px);
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 998;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sidebar - starts below header */
.sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 280px;
    height: calc(100vh - 60px);
    background: var(--primary-dark);
    color: white;
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s 0.4s,
                pointer-events 0s;
    z-index: 999;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    pointer-events: none;
    visibility: hidden;
}

/* Sidebar scrollable content */
.sidebar-header {
    flex-shrink: 0;
    height: 60px;
    padding: 0 1.25rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-nav-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav {
    padding: 1rem 0;
}

.sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s 0s,
                pointer-events 0s;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    margin: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.sidebar-title:hover {
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

/* Hamburger in sidebar */
.sidebar-header .hamburger {
    flex-shrink: 0;
}

/* Sidebar Navigation */

.sidebar-item {
    margin-bottom: 0.25rem;
    position: relative;
    overflow: visible;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    position: relative;
    border-left: 3px solid transparent;
}

.sidebar-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background: linear-gradient(180deg, #4CAF50, #2196F3);
    transform: scaleY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    padding-left: 1.5rem;
}

.sidebar-link:hover::before {
    transform: scaleY(1);
}

.sidebar-link svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.sidebar-link:hover svg {
    transform: scale(1.1) rotate(5deg);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.sidebar-link.has-submenu {
    justify-content: flex-start;
}

.sidebar-link.has-submenu > span {
    flex: 1;
    text-align: left;
}

.sidebar-link.has-submenu .submenu-arrow {
    margin-left: auto;
    flex-shrink: 0;
}

.submenu-arrow {
    width: 16px !important;
    height: 16px !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.6;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Sidebar Submenu - Flyout to the right */
/* Hide submenus completely when sidebar is closed */
.sidebar:not(.open) .sidebar-submenu {
    display: none !important;
}

.sidebar-submenu {
    position: fixed;
    left: 280px;
    min-width: 200px;
    background: var(--primary-dark);
    box-shadow: inset 8px 0 16px rgba(0, 0, 0, 0.3);
    border-radius: 0 0.75rem 0.75rem 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
    pointer-events: none;
    backdrop-filter: blur(10px);
}

/* Show submenu on hover - only when sidebar is open */
.sidebar.open .sidebar-item:hover > .sidebar-submenu {
    opacity: 1;
    visibility: visible;
    transform: translateX(0) scale(1);
    pointer-events: auto;
}

/* Animate arrow on hover - only when sidebar is open */
.sidebar.open .sidebar-item:hover .submenu-arrow {
    transform: translateX(5px);
    opacity: 1;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

.sidebar-submenu a {
    display: block;
    padding: 0.75rem 1.25rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    position: relative;
    border-left: 3px solid transparent;
}

.sidebar-submenu a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 0;
    background: linear-gradient(180deg, #4CAF50, #2196F3);
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 2px 2px 0;
}

.sidebar-submenu a:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    padding-left: 1.5rem;
}

.sidebar-submenu a:hover::before {
    height: 70%;
}

.sidebar-submenu a:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-submenu a:first-child {
    border-radius: 0 0.75rem 0 0;
}

.sidebar-submenu a:last-child {
    border-radius: 0 0 0.75rem 0;
}

/* ============================================
   SIMPLIFIED HEADER
   ============================================ */

.app-header-new {
    background: var(--primary-color);
    color: white;
    padding: 0;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 1002; /* Above sidebar (999) and submenus (1001) */
}

.header-content-new {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-title-new {
    font-size: 1.35rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    margin: 0;
    white-space: nowrap;
}

/* Header Icon Buttons */
.header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-icon-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.logout-form-new {
    margin: 0;
    padding: 0;
    display: inline-block;
}

/* Header Username */
.header-username {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0 0.75rem;
    white-space: nowrap;
    opacity: 0.9;
}

/* ============================================
   HAMBURGER MENU (Three-line → X animation)
   ============================================ */

.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    position: relative;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
    position: absolute;
}

.hamburger span:nth-child(1) {
    top: 12px;
}

.hamburger span:nth-child(2) {
    top: 19px;
}

.hamburger span:nth-child(3) {
    top: 26px;
}

.hamburger.active span:nth-child(1) {
    top: 19px;
    transform: rotate(45deg);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    top: 19px;
    transform: rotate(-45deg);
}

/* ============================================
   LANGUAGE SWITCHER IN HEADER (compact with dropdown)
   ============================================ */

.language-switcher {
    display: flex;
    align-items: center;
}

/* Compact wrapper */
.header-right .language-switcher .custom-select-wrapper {
    min-width: auto;
}

/* Hide text in trigger, show only globe + flag */
.header-right .language-switcher .custom-select-text {
    display: none;
}

/* Compact trigger - only globe + flag */
.header-right .language-switcher .custom-select-trigger {
    min-width: auto;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
    cursor: pointer;
}

.header-right .language-switcher .custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Globe icon */
.header-right .language-switcher .globe-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Smaller flag in trigger */
.header-right .language-switcher .custom-select-trigger .fi {
    width: 1em;
    height: 0.75em;
    font-size: 0.875rem;
}

.header-right .language-switcher .custom-select-arrow {
    display: none;
}

/* Dropdown options */
.header-right .language-switcher .custom-select-options {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: auto;
    min-width: 150px;
    background: var(--primary-dark);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.header-right .language-switcher .custom-select.open .custom-select-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Options in dropdown - show flag + text */
.header-right .language-switcher .custom-select-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.header-right .language-switcher .custom-select-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-right .language-switcher .custom-select-option.selected {
    background: rgba(255, 255, 255, 0.15);
}

.header-right .language-switcher .custom-select-option .fi {
    width: 1.5em;
    height: 1.125em;
    flex-shrink: 0;
}

.header-right .language-switcher .custom-select-option span:not(.fi) {
    font-size: 0.9rem;
}

/* ============================================
   SIDEBAR TRIGGER (Edge Tab Handle)
   ============================================ */

.sidebar-trigger:hover {
    background: var(--primary-dark) !important;
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.25) !important;
}

[dir="rtl"] .sidebar-trigger:hover {
    box-shadow: -3px 0 12px rgba(0, 0, 0, 0.25) !important;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
    }

    .app-title-new {
        font-size: 1.1rem;
    }

    .header-content-new {
        padding: 0 1rem;
    }

    /* Hide username on mobile */
    .header-username {
        display: none;
    }

    /* Hide trigger on mobile */
    #sidebarTrigger.sidebar-trigger {
        display: none !important;
    }

    /* Submenu accordion style for mobile */
    .sidebar-submenu {
        position: static;
        left: auto;
        min-width: auto;
        width: 100%;
        background: rgba(0, 0, 0, 0.2);
        box-shadow: none;
        border-radius: 0;
        border: none;
        max-height: 0;
        overflow: hidden;
        opacity: 1;
        visibility: visible;
        transform: none;
        transition: max-height 0.3s ease;
        pointer-events: auto;
        backdrop-filter: none;
    }

    /* Open submenu */
    .sidebar-item.submenu-open > .sidebar-submenu {
        max-height: 300px;
    }

    /* Disable hover opening on mobile - only when sidebar is open */
    .sidebar.open .sidebar-item:hover > .sidebar-submenu {
        opacity: 1;
        visibility: visible;
        transform: none;
        max-height: 0;
    }

    .sidebar.open .sidebar-item.submenu-open:hover > .sidebar-submenu {
        max-height: 300px;
    }

    /* Arrow rotates down */
    .submenu-arrow {
        transform: rotate(90deg);
    }

    /* Arrow when submenu is open */
    .sidebar.open .sidebar-item.submenu-open .submenu-arrow {
        transform: rotate(-90deg);
    }

    /* Disable arrow hover animation on mobile - only when sidebar is open */
    .sidebar.open .sidebar-item:hover .submenu-arrow {
        transform: rotate(90deg);
    }

    .sidebar.open .sidebar-item.submenu-open:hover .submenu-arrow {
        transform: rotate(-90deg);
    }

    /* Indent submenu items */
    .sidebar-submenu a {
        padding-left: 3rem;
    }

    .sidebar-submenu a:first-child {
        border-radius: 0;
    }

    .sidebar-submenu a:last-child {
        border-radius: 0;
    }
}
