/* Site Layout - Sidebar Navigation */

/* ============================================
   CORE LAYOUT STRUCTURE
   ============================================ */

/* HTML and Body base setup */
html {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* Body adjustments for site layout */
body.admin-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================
   TOP NAVIGATION BAR (HEADER)
   ============================================ */

.admin-topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    min-height: 56px;
    z-index: 1030;
    transition: left 0.3s ease, margin-left 0.3s ease, transform 0.3s ease;
    border-bottom: 1px solid #dee2e6;
}

/* Hide header when scrolling down */
.admin-topbar.header-hidden {
    transform: translateY(-100%);
}

/* Disable transition during page load */
body.preload .admin-topbar {
    transition: none !important;
}

/* Header positioning handled in desktop behavior section below */

/* Ensure navbar background extends when content wraps */
.admin-topbar .container-fluid {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Reduce header padding on mobile */
@media (max-width: 991.98px) {
    .admin-topbar .container-fluid {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }
}

/* White navbar styling */
.admin-topbar .navbar-brand {
    color: #212529 !important;
}

.admin-topbar .navbar-brand:hover {
    color: #0d6efd !important;
}

.admin-topbar .nav-link {
    color: #6c757d !important;
}

.admin-topbar .nav-link:hover {
    color: #212529 !important;
}

.admin-topbar .navbar-toggler {
    border: none !important;
}

.admin-topbar .navbar-toggler:focus {
    box-shadow: none !important;
}

.admin-topbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* ============================================
   SIDEBAR BACKDROP
   ============================================ */

.sidebar-overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1035;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay-backdrop.show {
    display: block;
    opacity: 1;
}

/* ============================================
   SIDEBAR
   ============================================ */

.admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px !important;
    max-width: 260px !important;
    background-color: #2c3e50;
    color: #ecf0f1;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid #34495e;
    z-index: 1040;
    transition: transform 0.3s ease;
}

/* Force width on offcanvas element */
.admin-sidebar.offcanvas {
    width: 260px !important;
    max-width: 260px !important;
}

/* Disable transition during page load */
body.preload .admin-sidebar {
    transition: none !important;
}

/* Sidebar Header with Branding */
.admin-sidebar .offcanvas-header {
    background-color: #1a252f;
    color: #ecf0f1;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #34495e;
    min-height: 70px;
    flex-shrink: 0;
}

.admin-sidebar .offcanvas-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.sidebar-brand-mobile {
    font-size: 1.25rem;
    font-weight: 700;
    color: #3498db;
    display: block !important; /* Always show branding in sidebar */
}

.sidebar-brand-mobile a:hover {
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

/* Sidebar Body */
.admin-sidebar .offcanvas-body {
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ============================================
   SIDEBAR BEHAVIOR - MOBILE (< 992px)
   ============================================ */

@media (max-width: 991.98px) {
    /* Mobile: Sidebar is hidden by default, slides in as overlay */
    .admin-sidebar {
        width: 280px;
        transform: translateX(-100%);
    }

    /* When offcanvas is shown */
    .admin-sidebar.show {
        transform: translateX(0);
    }

    /* Header stays full width on mobile */
    .admin-topbar {
        left: 0 !important;
    }

    /* Mobile header padding - reduced since search bar is now in overlay */
    body.admin-layout {
        padding-top: 60px;
    }

    /* Ensure backdrop appears behind menu but above content */
    .offcanvas-backdrop {
        z-index: 1035;
    }
}

/* ============================================
   SIDEBAR BEHAVIOR - DESKTOP (≥ 992px)
   ============================================ */

@media (min-width: 992px) {
    /* Desktop: Sidebar hidden by default */
    .admin-sidebar {
        width: 260px !important;
        max-width: 260px !important;
        transform: translateX(-100%) !important;
        visibility: visible !important;
    }

    /* When sidebar is temporarily open (unpinned) - OVERLAY mode */
    body.sidebar-temporary-open .admin-sidebar {
        transform: translateX(0) !important;
    }

    /* When sidebar is pinned - PUSH mode */
    body.sidebar-pinned .admin-sidebar {
        transform: translateX(0) !important;
    }

    /* Disable Bootstrap offcanvas on desktop - force our CSS */
    .admin-sidebar.offcanvas,
    .admin-sidebar.offcanvas.show,
    .admin-sidebar.offcanvas.showing,
    .admin-sidebar.offcanvas.hiding {
        position: fixed !important;
        visibility: visible !important;
    }

    /* Show backdrop when sidebar is temporarily open (unpinned) */
    body.sidebar-temporary-open .offcanvas-backdrop {
        display: block !important;
        opacity: 0.5;
    }

    /* No backdrop when sidebar is pinned */
    body.sidebar-pinned .offcanvas-backdrop {
        display: none !important;
    }

    /* No backdrop when sidebar is hidden */
    body.sidebar-hidden .offcanvas-backdrop {
        display: none !important;
    }

    /* PINNED mode: Header and content shift right */
    body.sidebar-pinned .admin-topbar {
        left: 260px !important;
    }

    body.sidebar-pinned .admin-content {
        margin-left: 260px !important;
    }

    body.sidebar-pinned .admin-footer {
        margin-left: 260px !important;
        width: calc(100% - 260px) !important;
    }

    /* OVERLAY mode: Header and content stay in place */
    body.sidebar-temporary-open .admin-topbar {
        left: 0 !important;
    }

    body.sidebar-temporary-open .admin-content {
        margin-left: 0 !important;
    }

    body.sidebar-temporary-open .admin-footer {
        margin-left: 0 !important;
    }

    /* Hide hamburger when sidebar is pinned (desktop only) */
    body.sidebar-pinned .navbar-toggler {
        display: none !important;
        visibility: hidden !important;
    }

    /* Show hamburger when sidebar is hidden or temporarily open (desktop only) */
    body.sidebar-hidden .navbar-toggler,
    body.sidebar-temporary-open .navbar-toggler {
        display: inline-block !important;
        visibility: visible !important;
    }

    /* Keep "RPG Market" text visible in header at all times on desktop */
    .navbar-brand {
        display: inline-block !important;
    }

    /* Hide "RPG Market" link in sidebar when pinned (redundant with header) */
    body.sidebar-pinned .sidebar-brand-mobile {
        display: none !important;
    }

    /* Show "RPG Market" link in sidebar when not pinned */
    body.sidebar-hidden .sidebar-brand-mobile,
    body.sidebar-temporary-open .sidebar-brand-mobile {
        display: block !important;
    }
}

/* ============================================
   MAIN CONTENT AREA
   ============================================ */

.admin-content {
    margin-left: 0;
    margin-top: 0;
    padding: 0.5rem;
    padding-top: 70px; /* Account for fixed header height */
    flex: 1;
    transition: margin-left 0.3s ease;
}

/* Disable transition during page load */
body.preload .admin-content {
    transition: none !important;
}

/* Content positioning handled in desktop behavior section */

/* Mobile: Content positioning */
@media (max-width: 991.98px) {
    .admin-content {
        margin-left: 0 !important;
        padding-top: 0.25rem !important; /* Body already has padding, don't add more */
    }
}

/* ============================================
   SIDEBAR NAVIGATION ITEMS
   ============================================ */

.sidebar-nav {
    padding: 0;
}

.sidebar-section-title {
    color: #95a5a6;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    background-color: #1a252f;
}

.sidebar-link,
.sidebar-section-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #ecf0f1;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
}

.sidebar-link:hover,
.sidebar-section-header:hover {
    background-color: #34495e;
    color: #ffffff;
    border-left-color: #3498db;
}

.sidebar-link.active,
.sidebar-section-header.active {
    background-color: #34495e;
    border-left-color: #3498db;
    color: #ffffff;
}

.sidebar-link i,
.sidebar-section-header i {
    width: 18px;
    margin-right: 0.625rem;
    text-align: center;
    font-size: 0.9rem;
}

/* Logout button styling */
.sidebar-link button,
form .sidebar-link {
    color: inherit;
    font-family: inherit;
    line-height: inherit;
}

/* ============================================
   SIDEBAR SECTIONS (COLLAPSIBLE)
   ============================================ */

.sidebar-section {
    margin: 0;
}

.sidebar-section-header {
    font-weight: 500;
    position: relative;
}

.sidebar-section-header .fa-chevron-down {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.sidebar-section-header:not(.collapsed) .fa-chevron-down {
    transform: rotate(180deg);
}

/* Sidebar Submenu */
.sidebar-submenu {
    background-color: #1a252f;
}

.sidebar-sublink {
    display: block;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    color: #bdc3c7 !important;
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.sidebar-sublink:link,
.sidebar-sublink:visited {
    color: #bdc3c7 !important;
}

.sidebar-sublink:hover {
    background-color: #34495e;
    color: #ffffff !important;
    padding-left: 2.75rem;
}

.sidebar-sublink.active {
    background-color: #34495e;
    color: #3498db;
    font-weight: 500;
}

.sidebar-sublink i {
    width: 14px;
    margin-right: 0.5rem;
    font-size: 0.8rem;
}

/* Nested submenu header (e.g., Logs header within System) */
.sidebar-nested-header {
    cursor: pointer;
    position: relative;
}

.sidebar-nested-header .fa-chevron-down {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.sidebar-nested-header:not(.collapsed) .fa-chevron-down {
    transform: rotate(180deg);
}

/* Nested submenu items (e.g., System Logs, Email Logs) */
.sidebar-nested-item {
    padding-left: 3.5rem;
}

.sidebar-nested-item:hover {
    padding-left: 3.75rem;
}

/* Sidebar Divider */
.sidebar-divider {
    margin: 0.4rem 1rem;
    border-color: #34495e;
    opacity: 0.5;
}

/* ============================================
   SIDEBAR SCROLLBAR STYLING
   ============================================ */

.admin-sidebar::-webkit-scrollbar {
    width: 6px;
}

.admin-sidebar::-webkit-scrollbar-track {
    background: #1a252f;
}

.admin-sidebar::-webkit-scrollbar-thumb {
    background: #34495e;
    border-radius: 3px;
}

.admin-sidebar::-webkit-scrollbar-thumb:hover {
    background: #4a5f7f;
}

/* ============================================
   SIDEBAR PIN BUTTON
   ============================================ */

#navPinToggle {
    font-size: 1rem;
    line-height: 1;
    border: none;
    background: transparent;
    transition: all 0.2s ease;
    text-decoration: none !important;
}

#navPinToggle:hover {
    opacity: 0.8;
}

#navPinToggle:focus {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

/* ============================================
   FOOTER
   ============================================ */

.admin-footer {
    margin-top: 0;
    margin-bottom: 0;
    margin-left: 0;
    margin-right: 0;
    padding: 1rem 0 !important;
    transition: margin-left 0.3s ease;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Ensure footer container-fluid has proper padding */
.admin-footer .container-fluid {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    max-width: 100%;
}

/* Reset row margins to prevent overflow */
.admin-footer .row {
    margin-left: 0;
    margin-right: 0;
}

/* Disable transition during page load */
body.preload .admin-footer {
    transition: none !important;
}

/* Footer positioning handled in desktop behavior section */

/* ============================================
   TOP NAVBAR ELEMENTS
   ============================================ */

/* User dropdown in top navbar */
.admin-topbar .dropdown-menu {
    margin-top: 0.5rem;
    min-width: 250px;
    z-index: 1026; /* Above dropdown backdrop */
}

.admin-topbar .dropdown-toggle::after {
    display: none;
}

.admin-topbar .dropdown-item {
    padding: 0.5rem 1rem;
}

.admin-topbar .dropdown-item i {
    width: 18px;
    margin-right: 0.5rem;
}

.admin-topbar .dropdown-item button {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    padding: 0;
    color: inherit;
    font: inherit;
}

.admin-topbar .dropdown-header {
    font-weight: 600;
    color: #495057;
    padding: 0.5rem 1rem;
}

.admin-topbar .nav-link {
    cursor: pointer;
    padding: 0.5rem;
}

.admin-topbar .nav-link:hover {
    opacity: 0.8;
}

/* Badge styling for white navbar */
.admin-topbar .badge {
    font-size: 0.65rem;
    padding: 0.25em 0.5em;
}

/* Custom gap for nav icons - 25% less than gap-3 (0.75rem instead of 1rem) */
.admin-topbar .nav-icons-container {
    gap: 0.75rem !important;
}

/* Search bar responsive width adjustments */
@media (min-width: 1200px) and (max-width: 1399.98px) {
    /* On screens between XL and XXL, reduce search bar width further */
    .admin-topbar form.position-absolute {
        width: 350px !important;
        max-width: 350px !important;
    }
}

/* Mobile: Add right padding to prevent icons from going off screen */
@media (max-width: 991.98px) {
    .admin-topbar .nav-icons-container {
        padding-right: 0.5rem;
        gap: 0.35rem !important; /* Even tighter spacing on mobile */
    }

    /* Reduce navbar brand (logo) size on mobile */
    .admin-topbar .navbar-brand {
        font-size: 1.5rem !important;
        margin-right: 0.25rem !important;
    }

    /* Reduce hamburger button size on mobile */
    .admin-topbar .navbar-toggler {
        padding: 0.25rem 0.35rem;
        margin-right: 0.25rem;
    }

    /* Slightly smaller icons on mobile */
    .admin-topbar .nav-link {
        padding: 0.35rem !important;
    }

    .admin-topbar .nav-link i.fa-lg {
        font-size: 1.1rem !important;
    }
}

/* Extra small screens: even more aggressive spacing */
@media (max-width: 575.98px) {
    .admin-topbar .nav-icons-container {
        padding-right: 0.25rem;
        gap: 0.25rem !important;
    }

    /* Smaller icons on very small screens */
    .admin-topbar .nav-link i.fa-lg {
        font-size: 1rem !important;
    }

    /* Further reduce navbar brand size */
    .admin-topbar .navbar-brand {
        font-size: 1.35rem !important;
    }

    /* Reduce hamburger button padding on mobile */
    .admin-topbar .navbar-toggler {
        padding: 0.2rem 0.3rem;
        margin-right: 0.2rem;
    }

    /* Tighter padding on nav links */
    .admin-topbar .nav-link {
        padding: 0.25rem !important;
    }
}

/* ============================================
   DROPDOWN MENU BACKDROP
   ============================================ */

.dropdown-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1025;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dropdown-backdrop.show {
    display: block;
    opacity: 1;
}

/* ============================================
   MOBILE SEARCH OVERLAY
   ============================================ */

.mobile-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-search-overlay.show {
    display: flex;
    opacity: 1;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
}

.mobile-search-container {
    background: white;
    border-radius: 0.5rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.mobile-search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #dee2e6;
}

.mobile-search-header h5 {
    margin: 0;
    font-weight: 600;
}

.mobile-search-body {
    padding: 1.5rem;
}

/* Hide search overlay on desktop */
@media (min-width: 1200px) {
    .mobile-search-overlay {
        display: none !important;
    }
}

/* ============================================
   ALERTS IN CONTENT AREA
   ============================================ */

.admin-content .alert {
    margin-bottom: 1.5rem;
}

/* ============================================
   PREVENT BODY SCROLL LOCK ISSUES
   ============================================ */

/* Ensure body can always scroll on desktop */
@media (min-width: 992px) {
    body {
        overflow-y: scroll !important;
    }

    /* Prevent Bootstrap from adding padding when modal opens on desktop
       since we're forcing scrollbar to always be visible */
    body.modal-open {
        padding-right: 0 !important;
    }
}

/* Allow body scroll lock on mobile (for offcanvas) */
@media (max-width: 991.98px) {
    body.modal-open,
    body.offcanvas-open {
        overflow: hidden;
    }
}
