/* =========================================================
   AdminLTE Sidebar RTL/LTR Support - Complete Fix
   ========================================================= */

/* ====================
   BASE DIRECTION SETUP
   ==================== */
html[dir="rtl"], html[dir="ltr"] {
    direction: inherit;
}

/* ====================
   SIDEBAR CONTAINER
   ==================== */
.main-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 1030;
    width: 250px;
    background: #f8f9fa;
    transition: all 0.3s ease-in-out;
    overflow-y: auto;
    overflow-x: hidden;
}

/* LTR: Sidebar on left */
html[dir="ltr"] .main-sidebar {
    left: 0;
    right: auto;
    border-right: 1px solid #dee2e6;
}

/* RTL: Sidebar on right */
html[dir="rtl"] .main-sidebar {
    right: 0;
    left: auto;
    border-left: 1px solid #dee2e6;
}

/* ====================
   BRAND LOGO AREA
   ==================== */
.brand-link {
    display: flex;
    align-items: center;
    padding: 1rem 1rem;
    font-size: 1.2rem;
    line-height: 1.5;
    color: #343a40;
    text-decoration: none;
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    transition: all 0.3s ease;
}

.brand-link:hover {
    text-decoration: none;
    background-color: #f8f9fa;
}

/* Brand image */
.brand-image {
    height: 33px;
    width: 33px;
    object-fit: contain;
    border-radius: 50%;
}

/* RTL brand layout */
html[dir="rtl"] .brand-link {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

html[dir="rtl"] .brand-image {
    margin-left: 0.75rem;
    margin-right: 0;
}

/* LTR brand layout */
html[dir="ltr"] .brand-link {
    flex-direction: row;
    justify-content: flex-start;
}

html[dir="ltr"] .brand-image {
    margin-right: 0.75rem;
    margin-left: 0;
}

.brand-text {
    font-weight: 300;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ====================
   SIDEBAR CONTENT
   ==================== */
.sidebar {
    height: calc(100vh - 56px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
}

/* Hide scrollbar but keep functionality */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ====================
   SEARCH BOX
   ==================== */
.form-inline {
    padding: 0.5rem 1rem;
}

.input-group {
    width: 100%;
}

.form-control-sidebar {
    border-radius: 0.375rem 0 0 0.375rem;
    border-right: 0;
}

.btn-sidebar {
    border-radius: 0 0.375rem 0.375rem 0;
    border-left: 0;
    background: #fff;
    border-color: #ced4da;
}

/* RTL search box */
html[dir="rtl"] .form-control-sidebar {
    border-radius: 0 0.375rem 0.375rem 0;
    border-left: 0;
    border-right: 1px solid #ced4da;
}

html[dir="rtl"] .btn-sidebar {
    border-radius: 0.375rem 0 0 0.375rem;
    border-right: 0;
}

/* ====================
   NAVIGATION MENU
   ==================== */
.nav-sidebar {
    list-style: none;
    padding-left: 0;
    padding-right: 0;
    margin-bottom: 0;
}

html[dir="rtl"] .nav-sidebar > .nav-item {
    margin: 0.125rem 0;
    text-align: right;
    cursor: pointer;
}

html[dir="ltr"] .nav-sidebar > .nav-item {
    margin: 0.125rem 0;
    text-align: left;
    cursor: pointer;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #495057;
    text-decoration: none;
    border-radius: 0.375rem;
    margin: 0 0.5rem;
    transition: all 0.2s ease;
    position: relative;
}

.nav-link:hover {
    background-color: #e9ecef;
    color: #495057;
}

.nav-link.active {
    background-color: green;
    color: white !important;
}

/* RTL nav link alignment */
html[dir="rtl"] .nav-link {
cursor: pointer;
}

html[dir="ltr"] .nav-link {
    flex-direction: row;
    justify-content: flex-start;
}

/* Nav icon */
.nav-icon {
    width: 1.25rem;
    text-align: center;
    font-size: 1.1rem;
}

html[dir="rtl"] .nav-icon {
    margin-left: 0.5rem;
    margin-right: 0;
}

html[dir="ltr"] .nav-icon {
    margin-right: 0.5rem;
    margin-left: 0;
}

/* Nav text */
.nav-link > p {
    margin: 0;
    flex: 1;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Right arrow/icon for menu groups */
.nav-link .right {
    font-size: 0.875rem;
    transition: transform 0.3s ease;
}

/* RTL arrow rotation */
html[dir="rtl"] .nav-link .right {
    transform: rotate(180deg);
    right:unset;
    left: 15px;
    top: 1rem;
}

html[dir="rtl"] .menu-open .nav-link .right {
    transform: rotate(90deg);
}

html[dir="ltr"] .menu-open .nav-link .right {
    transform: rotate(-90deg);
}

/* ====================
   MENU GROUPS (TREEVIEW)
   ==================== */
.nav-treeview {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Indentation for nested items */
html[dir="rtl"] .nav-treeview {
    padding-right: 2.5rem;
    padding-left: 0;
}

html[dir="ltr"] .nav-treeview {
    padding-left: 2.5rem;
    padding-right: 0;
}

.nav-treeview .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

/* RTL nested icon margin */
html[dir="rtl"] .nav-treeview .nav-icon {
    margin-left: 0.25rem;
}

html[dir="ltr"] .nav-treeview .nav-icon {
    margin-right: 0.25rem;
}

/* ====================
   USER PANEL
   ==================== */
.user-panel {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.user-panel .image {
    flex-shrink: 0;
}

.user-panel .image img {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    object-fit: cover;
}

.user-panel .info {
    flex: 1;
    padding: 0 0.75rem;
}

/* RTL user panel layout */
html[dir="rtl"] .user-panel {
    flex-direction: row-reverse;
}

html[dir="rtl"] .user-panel .info {
    padding: 0 0.75rem 0 0;
}

/* LTR user panel layout */
html[dir="ltr"] .user-panel {
    flex-direction: row;
}

html[dir="ltr"] .user-panel .info {
    padding: 0 0 0 0.75rem;
}

/* ====================
   CONTENT MARGINS
   ==================== */
/* When sidebar is present */
html[dir="ltr"] body:has(.main-sidebar:not(.d-none)) .content-wrapper,
html[dir="ltr"] body:has(.main-sidebar:not(.d-none)) .main-footer,
html[dir="ltr"] body:has(.main-sidebar:not(.d-none)) .main-header {
    margin-left: 250px;
    margin-right: 0px;

}

html[dir="rtl"] body:has(.main-sidebar:not(.d-none)) .content-wrapper,
html[dir="rtl"] body:has(.main-sidebar:not(.d-none)) .main-footer,
html[dir="rtl"] body:has(.main-sidebar:not(.d-none)) .main-header {
    margin-right: 250px;
    margin-left: 0 !important;
}

/* ====================
   RESPONSIVE DESIGN
   ==================== */

/* Tablet and mobile */
@media (max-width: 991.98px) {
    .main-sidebar {
        transform: translateX(0);
        box-shadow: 3px 0 6px rgba(0,0,0,0.1);
    }

    html[dir="rtl"] .main-sidebar {
        transform: translateX(100%);
        box-shadow: -3px 0 6px rgba(0,0,0,0.1);
    }

    .main-sidebar.show {
        transform: translateX(0);
    }

    /* Remove content margins on mobile */
    html[dir="ltr"] .content-wrapper,
    html[dir="ltr"] .main-footer,
    html[dir="ltr"] .main-header,
    html[dir="rtl"] .content-wrapper,
    html[dir="rtl"] .main-footer,
    html[dir="rtl"] .main-header {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Overlay when sidebar is open on mobile */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1029;
    }
}

/* Desktop collapsed sidebar */
@media (min-width: 992px) {
    body.sidebar-collapse .main-sidebar {
        width: 4.6rem;
    }

    body.sidebar-collapse .brand-text,
    body.sidebar-collapse .nav-link p,
    body.sidebar-collapse .nav-link .right {
        display: none;
    }

    body.sidebar-collapse .nav-link {
        justify-content: center;
        padding: 0.75rem;
    }

    /* Adjust content margins when collapsed */
    html[dir="ltr"] body.sidebar-collapse .content-wrapper,
    html[dir="ltr"] body.sidebar-collapse .main-footer,
    html[dir="ltr"] body.sidebar-collapse .main-header {
        margin-left: 4.6rem !important;
        margin-right: 0 !important;

    }

    html[dir="rtl"] body.sidebar-collapse .content-wrapper,
    html[dir="rtl"] body.sidebar-collapse .main-footer,
    html[dir="rtl"] body.sidebar-collapse .main-header {
        margin-right: 4.6rem !important;
        margin-left: 0 !important;
    }
}

/* ====================
   SPECIAL CLASSES
   ==================== */
/* Danger class for delete/trash */
.nav-link.bg-danger {
    background-color: #dc3545 !important;
    color: white !important;
}

.nav-link.bg-danger:hover {
    background-color: #c82333 !important;
}

/* Active state for menu groups */
.menu-open > .nav-link {
    background-color: #e9ecef;
    color: #495057;
}

/* ====================
   ANIMATIONS
   ==================== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.nav-treeview {
    animation: slideIn 0.3s ease-out;
}

/* ====================
   ACCESSIBILITY
   ==================== */
.nav-link:focus {
    outline: 2px solid green;
    outline-offset: -2px;
}

/* Keyboard navigation */
.nav-link.active:focus {
    outline-color: white;
}

/* ====================
   PRINT STYLES
   ==================== */
@media print {
    .main-sidebar {
        display: none !important;
    }

    html[dir="ltr"] .content-wrapper,
    html[dir="ltr"] .main-footer,
    html[dir="ltr"] .main-header,
    html[dir="rtl"] .content-wrapper,
    html[dir="rtl"] .main-footer,
    html[dir="rtl"] .main-header {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/* ====================
   DARK MODE SUPPORT
   ==================== */
@media (prefers-color-scheme: dark) {
    .main-sidebar {
        background: #2c3e50;
        border-color: #34495e;
    }

    .brand-link {
        background: #1a252f;
        color: #ecf0f1;
        border-color: #34495e;
    }

    .nav-link {
        color: #bdc3c7;
    }

    .nav-link:hover {
        background-color: #34495e;
    }

    .nav-link.active {
        background-color: #3498db;
    }

    .menu-open > .nav-link {
        background-color: #34495e;
    }

    .sidebar::-webkit-scrollbar-track {
        background: #34495e;
    }

    .sidebar::-webkit-scrollbar-thumb {
        background: #7f8c8d;
    }
}
