/* Mobile-only admin layout: simple, professional, and touch-friendly */
@media (max-width: 992px) {
    /* Admin portal root: stack vertically */
    #adminPortal.show {
        flex-direction: column;
    }

    /* Compact header for mobile — keep header inside flow to avoid positioning issues */
    .admin-header {
        position: relative !important;
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
        background: linear-gradient(90deg, #0b1020, #121a32);
        color: white;
        z-index: 10002;
    }
    .sidebar-header {
        position: relative !important;
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
        background: transparent;
        color: inherit;
        z-index: 10002;
    }

    /* Show the mobile hamburger (there is an existing element #mobileMenuBtn) */
    .mobile-menu-toggle { display: flex !important; align-items: center; justify-content: center; }

    /* Make hamburger touch area larger and keep it above content */
    .mobile-menu-toggle {
        position: fixed !important;
        top: calc(env(safe-area-inset-top, 12px)) !important;
        right: 12px !important;
        padding: 8px !important;
        width: 52px !important;
        height: 52px !important;
        box-sizing: border-box !important; /* include padding in hit area */
        z-index: 10003 !important;
        border-radius: 10px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(18, 26, 50, 0.92) !important;
        color: white !important;
        box-shadow: 0 4px 14px rgba(0,0,0,0.18) !important;
        pointer-events: auto !important;
    }

    /* Make the visible hamburger bars fill the button area so the touch target matches what users see */
    .mobile-menu-toggle span {
        display: block !important;
        width: 28px !important;
        height: 3px !important;
        background: white !important;
        margin: 3px 0 !important;
        border-radius: 2px !important;
    }

    /* Content: keep natural flow under header, but reserve space for fixed hamburger */
    .admin-main {
        margin-top: 0 !important;
        padding: 14px 16px 14px 14px !important;
        padding-right: 96px !important; /* reserve space for the menu button */
        overflow-x: hidden !important;
    }

    /* Ensure sidebar links are readable on white background */
    .admin-sidebar .sidebar-nav a,
    .admin-sidebar .sidebar-nav .sidebar-link,
    .admin-sidebar .sidebar-nav .sidebar-text {
        color: #1f2937 !important; /* dark slate color for readability */
    }

    /* Make icons slightly tinted and visible */
    .admin-sidebar .sidebar-nav .sidebar-icon {
        color: #d4af37 !important;
        opacity: 0.95;
        margin-right: 8px;
    }

    /* Ensure footer links and logout button are readable */
    .admin-sidebar .sidebar-footer a,
    .admin-sidebar .sidebar-footer .btn-logout {
        color: #1f2937 !important;
        background: transparent !important;
        border: none !important;
    }

    .admin-sidebar .sidebar-footer .btn-logout {
        display: block;
        width: 100%;
        text-align: center;
        padding: 10px 12px;
        border-radius: 8px;
        background: #f3f4f6 !important;
        color: #0b1020 !important;
        margin-top: 8px;
    }

    /* Keep the sidebar header inside the off-canvas panel (not fixed across page) */
    .admin-sidebar .sidebar-header {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        height: 56px;
        padding: calc(env(safe-area-inset-top, 8px) + 8px) 12px 8px 12px;
        align-items: center;
        display: flex;
        justify-content: space-between;
        background: transparent;
    }

    /* Logo/brand inside the sidebar should always be visible */
    .admin-sidebar .logo a {
        color: #0b1020 !important;
        font-weight: 700 !important;
        font-size: 1.05rem !important;
        text-decoration: none !important;
    }

    /* Sidebar becomes an off-canvas panel — align to top so it sits flush with the status bar */
    #adminSidebar, .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 78%;
        max-width: 360px;
        transform: translateX(-110%);
        transition: transform 280ms ease;
        background: #ffffff;
        box-shadow: 0 18px 40px rgba(0,0,0,0.15);
        z-index: 10001;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* When menu open, slide in */
    body.mobile-menu-open #adminSidebar, body.mobile-menu-open .admin-sidebar {
        transform: translateX(0);
    }

    /* Avoid double-offsets from multiple responsive stylesheets */
    .admin-content-wrapper {
        min-width: 0;
    }

    /* Overlay for dismissing menu */
    .mobile-overlay {
        display: block;
        position: fixed;
        inset: 0 0 0 0; /* cover full viewport */
        background: rgba(0,0,0,0.45);
        opacity: 0;
        transition: opacity 280ms ease;
        pointer-events: none;
        z-index: 10000;
    }
    body.mobile-menu-open .mobile-overlay { opacity: 1; pointer-events: auto; }

    /* Larger, comfortable tap targets inside sidebar */
    .admin-sidebar .sidebar-nav a, .admin-sidebar .sidebar-nav button, .admin-sidebar .sidebar-footer a {
        padding: 14px 18px !important;
        font-size: 1rem !important;
        display: block;
    }

    /* Hide desktop-only elements that break the mobile layout */
    .desktop-only { display: none !important; }

    /* Make inputs and buttons slightly larger on mobile for accessibility */
    button, input, select, textarea { font-size: 1rem; }

    /* Rooms & Inventory: prevent horizontal overflow in Manage form */
    #tab-rooms .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    #tab-rooms .section-header .btn {
        width: 100%;
    }

    #roomManagementContainer .room-management-card {
        padding: 1rem !important;
    }

    #roomManagementContainer .room-form-grid {
        grid-template-columns: 1fr !important;
    }

    #roomManagementContainer .room-form-actions {
        flex-direction: column;
    }

    #roomManagementContainer .room-form-actions .btn {
        width: 100%;
    }

    /* Rooms grid: single column on mobile */
    #tab-rooms .rooms-grid {
        grid-template-columns: 1fr !important;
        gap: 14px;
    }

    .room-inventory-card {
        padding: 16px;
    }

    .room-inventory-card h3 {
        font-size: 1.1rem;
    }

    .room-inventory-card .room-details p {
        word-break: break-word;
    }

    .room-inventory-card .room-inventory-actions {
        flex-direction: column;
    }

    .room-inventory-card .room-inventory-actions .btn {
        width: 100%;
    }

    /* Transparent hit area element that JS will create to make the full region tappable */
    .mobile-menu-hit { position: fixed; top: calc(env(safe-area-inset-top, 12px)); right: 12px; width: 72px; height: 72px; z-index: 10004; background: transparent; border-radius: 14px; pointer-events: auto; }
}

/* Additional narrow-breakpoint fixes for F&B / menu grids to avoid horizontal overflow */
@media (max-width: 420px) {
    .menu-items-grid, #orderMenuGrid, #staffMenuGrid, .staff-menu-grid {
        grid-template-columns: 1fr !important; /* stack to single column */
        gap: 0.5rem !important;
    }

    /* Ensure individual cards scale to container and do not create overflow */
    .menu-item-card, #orderMenuGrid .menu-item-card, .staff-menu-grid .menu-item-card {
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    /* Reduce right padding reserved for the hamburger to avoid forced horizontal space */
    #tabContent, .admin-main, #adminContent {
        padding-right: 16px !important;
    }

    /* Prevent any accidental horizontal scroll from transforms/padding */
    html, body {
        overflow-x: hidden !important;
    }

    /* Ensure F&B header action buttons wrap on small screens to avoid horizontal overflow */
    #tab-fnb .section-header > div,
    #tab-fnb .section-header div[style*="display: flex"] {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        align-items: center !important;
    }

    #tab-fnb .section-header > div .btn,
    #tab-fnb .section-header div[style*="display: flex"] .btn {
        flex: 1 1 auto !important;
        min-width: 0 !important; /* allow shrinking below content width */
        padding: 0.5rem 0.75rem !important;
        font-size: 0.95rem !important;
    }

    /* Prefer two-column layout when there's room, otherwise stack */
    #tab-fnb .section-header > div .btn:nth-child(1),
    #tab-fnb .section-header > div .btn:nth-child(2) {
        max-width: 48% !important;
    }
    #tab-fnb .section-header > div .btn:nth-child(n+3) {
        max-width: 48% !important;
    }
}
