/* แก้ไขปัญหาสีตัวหนังสือสีขาวใน sidebar - ใช้ specificity สูงสุด */
html body.skin-blue .sidebar a,
html body.skin-blue .sidebar-menu a,
html body.skin-blue .sidebar-menu li a,
html body.skin-blue .sidebar-menu>li>a,
html body.skin-blue .sidebar-menu>li>a>span {
    color: #333 !important;
    /* เปลี่ยนจากสีขาวเป็นสีเทาเข้ม */
}

html body.skin-blue .sidebar a:hover,
html body.skin-blue .sidebar-menu a:hover,
html body.skin-blue .sidebar-menu li a:hover,
html body.skin-blue .sidebar-menu>li>a:hover,
html body.skin-blue .sidebar-menu>li>a:hover>span {
    color: #000 !important;
    /* สีเมื่อ hover */
    text-decoration: none;
}

html body.skin-blue .treeview-menu>li>a,
html body.skin-blue .sidebar-menu .treeview-menu>li>a,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>span {
    color: #555 !important;
    /* สีตัวหนังสือใน submenu */
}

html body.skin-blue .treeview-menu>li.active>a,
html body.skin-blue .treeview-menu>li>a:hover,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>span,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>span {
    color: #000 !important;
    /* สีเมื่อ active หรือ hover */
    background-color: #f0f0f0 !important;
}

/* เพิ่มเส้นขอบให้เห็นชัดเจน */
html body.skin-blue .sidebar-menu>li>a {
    border-bottom: 1px solid #ddd !important;
    /* เส้นขอบด้านล่าง */
    border-left: 3px solid transparent !important;
    /* เส้นขอบด้านซ้าย */
}

html body.skin-blue .sidebar-menu>li.active>a {
    border-left-color: #3c8dbc !important;
    /* เส้นขอบด้านซ้ายเมื่อ active */
    background-color: #f8f9fa !important;
}

html body.skin-blue .sidebar-menu>li>.treeview-menu {
    border-left: 3px solid #ccc !important;
    /* เส้นขอบด้านซ้ายของ submenu */
    margin-left: 10px !important;
    background-color: #f8f9fa !important;
}

html body.skin-blue .sidebar-menu>li>.treeview-menu>li>a {
    border-bottom: 1px solid #eee !important;
    /* เส้นขอบสำหรับ submenu items */
    padding: 8px 15px !important;
}

/* ปรับปรุงสีพื้นหลังของ sidebar */
html body.skin-blue .main-sidebar,
html body.skin-blue .left-side {
    background-color: #f8f9fa !important;
    /* พื้นหลังสีอ่อน */
}

/* ปรับสีของ header ใน sidebar */
html body.skin-blue .sidebar-menu>li.header {
    color: #666 !important;
    background: #e9ecef !important;
    font-weight: bold !important;
}

/* แก้ไขสีตัวหนังสือใน user panel */
html body.skin-blue .user-panel>.info,
html body.skin-blue .user-panel>.info>a {
    color: #333 !important;
}

/* แก้ไขสีตัวหนังสือใน sidebar form */
html body.skin-blue .sidebar-form input[type="text"] {
    color: #333 !important;
    background-color: #fff !important;
}

/* แก้ไขสีตัวหนังสือใน sidebar form เมื่อ focus */
html body.skin-blue .sidebar-form input[type="text"]:focus {
    color: #333 !important;
    background-color: #fff !important;
}

/* แก้ไขสีตัวหนังสือใน sidebar form button */
html body.skin-blue .sidebar-form .btn {
    color: #333 !important;
}

/* แก้ไขปัญหาสีตัวหนังสือสีขาวใน sidebar - ใช้ specificity สูงสุดและครอบคลุมทุกกรณี */
html body.skin-blue .sidebar *,
html body.skin-blue .sidebar-menu *,
html body.skin-blue .sidebar-menu li *,
html body.skin-blue .sidebar-menu>li *,
html body.skin-blue .sidebar-menu>li>a *,
html body.skin-blue .sidebar-menu>li>a>span,
html body.skin-blue .sidebar-menu>li>a>i,
html body.skin-blue .sidebar-menu>li>a>.fa,
html body.skin-blue .sidebar-menu>li>a>.glyphicon,
html body.skin-blue .sidebar-menu>li>a>.ion {
    color: #333 !important;
    /* เปลี่ยนจากสีขาวเป็นสีเทาเข้ม */
}

html body.skin-blue .treeview-menu *,
html body.skin-blue .sidebar-menu .treeview-menu *,
html body.skin-blue .sidebar-menu .treeview-menu>li *,
html body.skin-blue .sidebar-menu .treeview-menu>li>a *,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>span,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>i,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>.fa,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>.glyphicon,
html body.skin-blue .sidebar-menu .treeview-menu>li>a>.ion {
    color: #555 !important;
    /* สีตัวหนังสือใน submenu */
}

/* แก้ไขสีเมื่อ hover และ active */
html body.skin-blue .sidebar *:hover,
html body.skin-blue .sidebar-menu *:hover,
html body.skin-blue .sidebar-menu li *:hover,
html body.skin-blue .sidebar-menu>li *:hover,
html body.skin-blue .sidebar-menu>li>a:hover *,
html body.skin-blue .sidebar-menu>li>a:hover>span,
html body.skin-blue .sidebar-menu>li>a:hover>i,
html body.skin-blue .sidebar-menu>li>a:hover>.fa,
html body.skin-blue .sidebar-menu>li>a:hover>.glyphicon,
html body.skin-blue .sidebar-menu>li>a:hover>.ion {
    color: #000 !important;
    /* สีเมื่อ hover */
}

html body.skin-blue .treeview-menu *:hover,
html body.skin-blue .sidebar-menu .treeview-menu *:hover,
html body.skin-blue .sidebar-menu .treeview-menu>li *:hover,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover *,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>span,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>i,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>.fa,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>.glyphicon,
html body.skin-blue .sidebar-menu .treeview-menu>li>a:hover>.ion {
    color: #000 !important;
    /* สีเมื่อ hover ใน submenu */
}

/* แก้ไขสีเมื่อ active */
html body.skin-blue .sidebar-menu>li.active *,
html body.skin-blue .sidebar-menu>li.active>a *,
html body.skin-blue .sidebar-menu>li.active>a>span,
html body.skin-blue .sidebar-menu>li.active>a>i,
html body.skin-blue .sidebar-menu>li.active>a>.fa,
html body.skin-blue .sidebar-menu>li.active>a>.glyphicon,
html body.skin-blue .sidebar-menu>li.active>a>.ion {
    color: #000 !important;
    /* สีเมื่อ active */
}

html body.skin-blue .sidebar-menu .treeview-menu>li.active *,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a *,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>span,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>i,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>.fa,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>.glyphicon,
html body.skin-blue .sidebar-menu .treeview-menu>li.active>a>.ion {
    color: #000 !important;
    /* สีเมื่อ active ใน submenu */
}

/* ==========================================================================
   FIX: Prevent sidebar expansion on hover when collapsed & Show Floating Menu
   ========================================================================== */

@media (min-width: 768px) {

    /* 1. Prevent sidebar from expanding - MUST target :hover explicitly to override AdminLTE */
    /* Also set overflow: visible so the popup menu can "escape" the narrow sidebar container */
    .sidebar-mini.sidebar-collapse .main-sidebar,
    .sidebar-mini.sidebar-collapse .main-sidebar:hover {
        width: 50px !important;
        z-index: 850;
        overflow: visible !important;
    }

    .sidebar-mini.sidebar-collapse .sidebar {
        overflow: visible !important;
        width: 50px !important;
    }

    /* 2. Hide the original text label and submenu initially */
    /* Use > a > span for strict targeting of labels */
    .sidebar-mini.sidebar-collapse .sidebar-menu>li>a>span,
    .sidebar-mini.sidebar-collapse .sidebar-menu>li>.treeview-menu {
        display: none !important;
        visibility: hidden !important;
        /* Extra safety */
    }

    /* 3. Show Title on Hover (Floating tooltip style) */
    .sidebar-mini.sidebar-collapse .sidebar-menu>li:hover>a>span {
        display: block !important;
        visibility: visible !important;
        position: absolute;
        top: 0;
        left: 50px;
        /* Align precisely next to sidebar */
        padding: 12px 20px;
        background-color: #f8f9fa;
        /* Match sidebar background */
        color: #333 !important;
        width: 230px;
        /* Fixed width for the popup */
        border: 1px solid #d2d6de;
        /* Matches AdminLTE border color often */
        border-left: none;
        /* Seamless connection */
        box-shadow: 3px 0 5px rgba(0, 0, 0, 0.15);
        z-index: 9999;
        /* High z-index to sit on top of everything */
        white-space: nowrap;
        /* Prevent line break */
        border-radius: 0 4px 0 0;
        /* Slight rounding on top right */
    }

    /* 4. Show Submenu on Hover (Floating below the title) */
    .sidebar-mini.sidebar-collapse .sidebar-menu>li:hover>.treeview-menu {
        display: block !important;
        visibility: visible !important;
        position: absolute;
        top: 44px;
        /* Stack below title */
        left: 50px;
        width: 230px;
        margin: 0 !important;
        background-color: #f8f9fa !important;
        border: 1px solid #d2d6de;
        border-top: 1px solid #eee;
        box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.15);
        z-index: 9998;
        padding-left: 0;
        border-radius: 0 0 4px 4px;
        /* Slight rounding on bottom */
    }

    /* Ensure submenu items are nicely padded and text color is correct */
    .sidebar-mini.sidebar-collapse .sidebar-menu>li:hover>.treeview-menu>li>a {
        padding-left: 20px !important;
        color: #333 !important;
    }

    .sidebar-mini.sidebar-collapse .sidebar-menu>li:hover>.treeview-menu>li>a:hover {
        background-color: #e9ecef !important;
    }
}