/* ── Layout Outer Wrapper ────────────────────────────── */
.layout-wrapper {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - var(--navbar-height, 60px));
    position: relative;
    width: 100%;
}

/* ── Sidebar Column Container ────────────────────────── */
.sidebar-col {
    flex: 0 0 240px;
    max-width: 240px;
    position: sticky;
    top: var(--navbar-height, 60px);
    height: calc(100vh - var(--navbar-height, 60px));
    transition:
        flex 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        max-width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1020;
}

/* ── Sidebar Card Styling ───────────────────────────── */
.sidebar-card {
    height: 100% !important;
    min-height: 100% !important;
    background-color: var(--bg-card, #ffffff) !important;
    border-right: 1px solid var(--border-color, #e5e7eb) !important;
    box-shadow: 4px 0 16px -12px
        var(--shadow-color-strong, rgba(0, 0, 0, 0.15));
    color: var(--text-primary, #1f2937) !important;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    border-radius: 0 !important;
}

.sidebar-card .card-body {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    padding: 1rem 0.75rem !important;
}

.sidebar-card::-webkit-scrollbar {
    width: 4px;
}

.sidebar-card::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

/* ── Sidebar Header ──────────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.25rem 1rem 0.25rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    margin-bottom: 0.75rem;
    width: 100%;
}

.sidebar-brand-logo {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    text-decoration: none;
    min-width: 0;
    overflow: hidden;
}

.sidebar-logo-img {
    width: 26px;
    height: 26px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 4px;
}

.sidebar-logo-text {
    white-space: nowrap;
}

/* ── Hamburger Button ───────────────────────────────── */
.sidebar-toggle-btn {
    border: none;
    background: transparent;
    color: var(--text-primary, #1f2937);
    font-size: 1.35rem;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    visibility: visible !important;
    opacity: 1 !important;
    transition: background-color 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background-color: var(--bg-hover, #f3f4f6);
}

/* ══════════════════════════════════════════════════════
   SIDEBAR NAVIGATION
   ══════════════════════════════════════════════════════ */

.sidebar-nav {
    flex: 1 1 auto;
}

/* ── Section Labels ──────────────────────────────────── */
.sidebar-section {
    margin-bottom: 0.4rem;
}

.sidebar-section-label {
    display: block;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted, #6c757d);
    padding: 0.55rem 0.85rem 0.3rem;
    white-space: nowrap;
    overflow: hidden;
}

/* ── Nav Item ────────────────────────────────────────── */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.42rem 0.7rem;
    margin-bottom: 2px;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary, #1f2937) !important;
    text-decoration: none;
    width: 100%;
    white-space: nowrap;
    position: relative;
    transition:
        background-color 0.18s ease,
        color 0.18s ease,
        transform 0.18s ease;
}

/* ── Nav Icon ────────────────────────────────────────── */
.sidebar-nav-item .sidebar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 9px;
    background: var(--bg-hover, #f1f3f5);
    color: var(--text-muted, #6c757d);
    font-size: 1.05rem;
    flex-shrink: 0;
    transition:
        background-color 0.18s ease,
        color 0.18s ease,
        box-shadow 0.18s ease;
}

.sidebar-nav-item .sidebar-link-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Hover ───────────────────────────────────────────── */
.sidebar-nav-item:hover:not(.active) {
    background-color: var(--bg-hover, #f1f3f5);
    color: var(--text-primary, #111827) !important;
    transform: translateX(2px);
}

.sidebar-nav-item:hover:not(.active) .sidebar-icon {
    background: rgba(4, 155, 9, 0.10);
    color: var(--brand-green, #049b09);
}

/* ── Active ──────────────────────────────────────────── */
.sidebar-nav-item.active {
    background: rgba(4, 155, 9, 0.10) !important;
    color: var(--brand-green, #049b09) !important;
    font-weight: 600;
}

.sidebar-nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 58%;
    border-radius: 0 4px 4px 0;
    background: var(--brand-green, #049b09);
}

.sidebar-nav-item.active .sidebar-icon {
    background: var(--brand-green, #049b09) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(4, 155, 9, 0.35);
}

/* ── Count Badges ────────────────────────────────────── */
.sidebar-nav-item .sidebar-badge {
    margin-left: auto;
    min-width: 19px;
    height: 19px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border-radius: 10px;
    background: #dc2626;
    color: #ffffff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

/* ── Logout ──────────────────────────────────────────── */
.sidebar-nav-item.logout-item:hover:not(.active) {
    color: #dc2626 !important;
}

.sidebar-nav-item.logout-item:hover:not(.active) .sidebar-icon {
    background: rgba(220, 38, 38, 0.10);
    color: #dc2626;
}

/* ── Profile ─────────────────────────────────────────── */
.sidebar-profile {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.sidebar-profile-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.7rem;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-primary, #1f2937) !important;
    transition: background-color 0.18s ease;
}

.sidebar-profile-link:hover {
    background-color: var(--bg-hover, #f1f3f5);
}

.sidebar-avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(
        135deg,
        var(--brand-green, #049b09),
        var(--brand-green-light, #56dd59)
    );
    color: #ffffff;
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(4, 155, 9, 0.30);
}

.sidebar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-profile-info {
    min-width: 0;
    flex: 1 1 auto;
}

.sidebar-profile-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-profile-role {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted, #6c757d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-profile-gear {
    margin-left: auto;
    color: var(--text-muted, #6c757d);
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-profile-link:hover .sidebar-profile-gear {
    color: var(--brand-green, #049b09);
}

/* ── Main Content ────────────────────────────────────── */
.content-col {
    flex: 1 1 auto;
    min-width: 0;
    background-color: var(--bg-body, #f9fafb);
    padding: 1.5rem;
}

/* ══════════════════════════════════════════════════════
   DESKTOP SIDEBAR COLLAPSE
   ══════════════════════════════════════════════════════ */

@media (min-width: 768px) {

    .layout-wrapper.collapsed .sidebar-col {
        flex: 0 0 72px;
        max-width: 72px;
    }

    .layout-wrapper.collapsed .sidebar-card .card-body {
        padding: 1rem 0.3rem !important;
        align-items: center;
    }

    /* Hide text in collapsed desktop sidebar */
    .layout-wrapper.collapsed .sidebar-logo-text,
    .layout-wrapper.collapsed .sidebar-link-text,
    .layout-wrapper.collapsed .badge-text,
    .layout-wrapper.collapsed .sidebar-section-label,
    .layout-wrapper.collapsed .sidebar-profile-info,
    .layout-wrapper.collapsed .sidebar-profile-gear,
    .layout-wrapper.collapsed .sidebar-badge {
        display: none !important;
    }

    .layout-wrapper.collapsed .sidebar-header {
        flex-direction: column;
        justify-content: center !important;
        align-items: center;
        gap: 8px;
        padding: 0 0 1rem 0 !important;
    }

    .layout-wrapper.collapsed .sidebar-brand-logo {
        justify-content: center !important;
        width: 100%;
    }

    .layout-wrapper.collapsed .sidebar-logo-img {
        margin: 0 auto;
    }

    .layout-wrapper.collapsed .sidebar-toggle-btn {
        margin: 0 auto !important;
    }

    .layout-wrapper.collapsed .sidebar-nav-item {
        justify-content: center !important;
        padding: 0.35rem !important;
        width: 44px;
        height: 44px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 4px;
        gap: 0;
    }

    .layout-wrapper.collapsed .sidebar-nav-item:hover {
        transform: none;
    }

    .layout-wrapper.collapsed .sidebar-nav-item.active::before {
        display: none;
    }

    .layout-wrapper.collapsed .sidebar-nav-item .sidebar-icon {
        width: 34px;
        height: 34px;
        min-width: 34px;
        border-radius: 9px;
        font-size: 1.1rem !important;
    }

    .layout-wrapper.collapsed .sidebar-profile-link {
        justify-content: center !important;
        padding: 0.35rem !important;
    }

    .layout-wrapper.collapsed .sidebar-avatar {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
}


/* ══════════════════════════════════════════════════════
   MOBILE SIDEBAR
   IMPORTANT:
   Mobile default = ICON SIDEBAR
   Hamburger = opens FULL SIDEBAR
   ══════════════════════════════════════════════════════ */

@media (max-width: 767.98px) {

    /* ──────────────────────────────────────────────────
       DEFAULT MOBILE STATE
       Keep sidebar visible with icons (52px - just icons).
       ────────────────────────────────────────────────── */

    .layout-wrapper:not(.mobile-open) .sidebar-col {
        flex: 0 0 52px;
        max-width: 52px;
        width: 52px;
        position: sticky;
        top: var(--navbar-height, 60px);
        height: calc(100vh - var(--navbar-height, 60px));
        z-index: 1020;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-card {
        width: 100%;
        height: 100%;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-card .card-body {
        padding: 0.5rem 0.15rem !important;
        align-items: center;
    }

    /* ── Header ──────────────────────────────────────── */

    .layout-wrapper:not(.mobile-open) .sidebar-header {
        flex-direction: column;
        justify-content: center !important;
        align-items: center;
        gap: 6px;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
        margin-bottom: 0.5rem;
        padding: 0 0 0.5rem 0 !important;
    }

    /* Match desktop's collapsed rail: keep the small logo icon visible
       (only the text label hides), instead of hiding the whole brand
       block. This is what was missing the "gap"/logo that desktop's
       collapsed sidebar has above the nav icons. */
    .layout-wrapper:not(.mobile-open) .sidebar-brand-logo {
        display: flex !important;
        justify-content: center;
        width: 100%;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-logo-text {
        display: none !important;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-logo-img {
        width: 22px;
        height: 22px;
    }

    /* Hamburger stays visible */
    .layout-wrapper:not(.mobile-open) .sidebar-toggle-btn {
        display: inline-flex !important;
        width: 36px;
        height: 36px;
        margin: 0 auto !important;
        padding: 2px;
    }

    /* ── Navigation stays visible ────────────────────── */

    .layout-wrapper:not(.mobile-open) .sidebar-nav {
        display: block !important;
        width: 100%;
        flex: 1 1 auto;
    }

    /* Hide all text, keep icons */
    .layout-wrapper:not(.mobile-open) .sidebar-section-label,
    .layout-wrapper:not(.mobile-open) .sidebar-link-text,
    .layout-wrapper:not(.mobile-open) .badge-text,
    .layout-wrapper:not(.mobile-open) .sidebar-badge {
        display: none !important;
    }

    /* Icon-only navigation - touch-friendly 44x44 minimum */
    .layout-wrapper:not(.mobile-open) .sidebar-nav-item {
        display: flex;
        justify-content: center !important;
        align-items: center;
        width: 44px;
        height: 44px;
        padding: 0.25rem !important;
        margin: 0 auto 5px auto;
        gap: 0;
        border-radius: 10px;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-nav-item:hover {
        transform: none;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-nav-item.active::before {
        display: none;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-nav-item .sidebar-icon {
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 8px;
        font-size: 1rem !important;
        margin: 0 !important;
    }

    /* ── Profile stays visible at bottom ─────────────── */

    .layout-wrapper:not(.mobile-open) .sidebar-profile {
        display: block !important;
        width: 100%;
        margin-top: auto;
        padding-top: 0.5rem;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-profile-link {
        justify-content: center !important;
        padding: 0.25rem !important;
        width: 100%;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-avatar {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    /* Hide profile text/settings but keep avatar */
    .layout-wrapper:not(.mobile-open) .sidebar-profile-info,
    .layout-wrapper:not(.mobile-open) .sidebar-profile-gear {
        display: none !important;
    }


    /* ──────────────────────────────────────────────────
       MOBILE FULL SIDEBAR
       Opens when .mobile-open is added.
       ────────────────────────────────────────────────── */

    .layout-wrapper.mobile-open .sidebar-col {
        position: fixed;
        top: var(--navbar-height, 60px);
        left: 0;
        flex: none;
        width: 240px;
        max-width: 240px;
        height: calc(100vh - var(--navbar-height, 60px));
        z-index: 1050;
        box-shadow:
            8px 0 24px -8px
            var(--shadow-color-strong, rgba(0, 0, 0, 0.35));
    }

    .layout-wrapper.mobile-open .sidebar-card .card-body {
        padding: 1rem 0.75rem !important;
        align-items: flex-start;
    }

    /* Restore full sidebar content */
    .layout-wrapper.mobile-open .sidebar-brand-logo,
    .layout-wrapper.mobile-open .sidebar-nav,
    .layout-wrapper.mobile-open .sidebar-profile {
        display: block !important;
    }

    .layout-wrapper.mobile-open .sidebar-brand-logo {
        display: flex !important;
    }

    .layout-wrapper.mobile-open .sidebar-nav {
        display: block !important;
        width: 100%;
    }

    .layout-wrapper.mobile-open .sidebar-profile {
        display: block !important;
    }

    .layout-wrapper.mobile-open .sidebar-logo-text,
    .layout-wrapper.mobile-open .sidebar-link-text,
    .layout-wrapper.mobile-open .sidebar-section-label,
    .layout-wrapper.mobile-open .sidebar-profile-info,
    .layout-wrapper.mobile-open .sidebar-profile-gear {
        display: inline !important;
    }

    .layout-wrapper.mobile-open .badge-text:not(.d-none) {
        display: inline-block !important;
    }

    .layout-wrapper.mobile-open .badge-text.d-none {
        display: none !important;
    }

    /* Header: was `justify-content: space-between !important`, which
       shoved the hamburger to the far left edge and the SafhaSahar logo
       to the far right edge — a big dead gap in between that looked
       broken next to the desktop header (hamburger + logo sitting close
       together with a small gap). Matching the desktop grouping here. */
    .layout-wrapper.mobile-open .sidebar-header {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 0.5rem;
        padding: 0 0.25rem 1rem 0.25rem !important;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
    }

    .layout-wrapper.mobile-open .sidebar-nav-item {
        justify-content: flex-start !important;
        width: 100%;
        height: auto;
        padding: 0.42rem 0.7rem !important;
        margin: 0 0 2px 0;
        gap: 0.7rem;
    }

    .layout-wrapper.mobile-open .sidebar-nav-item .sidebar-icon {
        width: 34px;
        height: 34px;
        min-width: 34px;
        margin-right: 0 !important;
    }


    /* ──────────────────────────────────────────────────
       MOBILE BACKDROP
       ────────────────────────────────────────────────── */

    .sidebar-backdrop {
        display: none;
    }

    .sidebar-backdrop.active {
        display: block;
        position: fixed;
        top: var(--navbar-height, 60px);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 1040;
        animation: sidebar-backdrop-fade 0.2s ease;
    }

    @keyframes sidebar-backdrop-fade {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }


    /* ──────────────────────────────────────────────────
       MOBILE CONTENT
       ────────────────────────────────────────────────── */

    .content-col {
        padding: 1rem 0.65rem;
        min-width: 0;
        overflow-x: hidden;
    }

    #content-app .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 0.75rem !important;
        max-width: 100%;
    }
}


/* ── EXTRA SMALL MOBILE ──────────────────────────────── */

@media (max-width: 575.98px) {

    .layout-wrapper:not(.mobile-open) .sidebar-col {
        flex: 0 0 62px;
        max-width: 62px;
        width: 62px;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-nav-item {
        width: 42px;
        height: 42px;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-nav-item .sidebar-icon {
        width: 34px;
        height: 34px;
        min-width: 34px;
        font-size: 1.05rem !important;
    }

    .layout-wrapper:not(.mobile-open) .sidebar-avatar {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .content-col {
        padding: 0.75rem 0.5rem;
    }

    
    #content-app .container-fluid {
        padding-left: 0.6rem !important;
        padding-right: 0.6rem !important;
    }
}